Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:59:41+00:00 2026-05-26T00:59:41+00:00

i have a problem with a mysql ERM which is currently driving me crazy.

  • 0

i have a problem with a mysql ERM which is currently driving me crazy. I have a table called usuaris_backoffice used to store backoffice users, then i also have a table called usuaris_backoffice_permisos used to store the privileges of every user. I also have a table called perfils where i store some profiles which can be edited by the backoffice users so to have a edition history there is a tabled called perfils_usuari_backoffice where i store which profile has been modified by each user. Then i also have a tabled called widgets which also can be edited by the users, so the widgets edition history is stored in widgets_usuari_backoffice. The FK are enabled for cascade deletion, so when a user is deleted from usuaris_backoffice its privileges are also deleted from usuaris_backoffice_permisos. The problem appears when i try to:

 truncate usuaris_backoffice_permisos

which gives me the following error:

 1701 - Cannot truncate a table referenced in a foreign key constraint (`test`.`usuaris_backoffice_permisos`, CONSTRAINT `FK_F8F850F3D001730C` FOREIGN KEY (`usuari_backoffice_id`) REFERENCES `test`.`usuaris_backoffice` (`id`)) 

As this 6 tables are part of a biggest ERM i’ve created a small test environment in order to be able to run some tests, so the following code can be used to create and populate the tables:

CREATE TABLE perfils_usuari_backoffice (perfil_id INT NOT NULL, login VARCHAR(20) NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_870785D657291544 (perfil_id), INDEX IDX_870785D6AA08CB10 (login), PRIMARY KEY(perfil_id, login, updated_at)) ENGINE = InnoDB;
CREATE TABLE usuaris_backoffice (id INT AUTO_INCREMENT NOT NULL, login VARCHAR(20) NOT NULL, password VARCHAR(32) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_95E4B6E5AA08CB10 (login), PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE usuaris_backoffice_permisos (id INT AUTO_INCREMENT NOT NULL, usuari_backoffice_id INT NOT NULL, es_admin TINYINT(1) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_F8F850F3D001730C (usuari_backoffice_id), PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE widgets_usuari_backoffice (widget_id INT NOT NULL, usuari_backoffice_id INT NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_43DA3B33FBE885E2 (widget_id), INDEX IDX_43DA3B33D001730C (usuari_backoffice_id), PRIMARY KEY(widget_id, usuari_backoffice_id, updated_at)) ENGINE = InnoDB;
CREATE TABLE widgets (id INT AUTO_INCREMENT NOT NULL, classe VARCHAR(20) NOT NULL, updated_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_9D58E4C18F87BF96 (classe), PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE perfils (id INT AUTO_INCREMENT NOT NULL, actiu TINYINT(1) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;

ALTER TABLE perfils_usuari_backoffice ADD CONSTRAINT FK_870785D657291544 FOREIGN KEY (perfil_id) REFERENCES perfils (id) ON DELETE CASCADE;
ALTER TABLE usuaris_backoffice_permisos ADD CONSTRAINT FK_F8F850F3D001730C FOREIGN KEY (usuari_backoffice_id) REFERENCES usuaris_backoffice (id) ON DELETE CASCADE;
ALTER TABLE perfils_usuari_backoffice ADD CONSTRAINT FK_870785D6AA08CB10 FOREIGN KEY (login) REFERENCES usuaris_backoffice (login) ON DELETE CASCADE;
ALTER TABLE widgets_usuari_backoffice ADD CONSTRAINT FK_43DA3B33D001730C FOREIGN KEY (usuari_backoffice_id) REFERENCES usuaris_backoffice (id) ON DELETE CASCADE;
ALTER TABLE widgets_usuari_backoffice ADD CONSTRAINT FK_43DA3B33FBE885E2 FOREIGN KEY (widget_id) REFERENCES widgets (id) ON DELETE CASCADE;

INSERT INTO `test`.`usuaris_backoffice` (`id` ,`login` ,`password` ,`created_at` ,`updated_at`)VALUES (NULL , 'edgar', '1234', '2011-10-06 00:00:00', '2011-10-06 00:00:00');
INSERT INTO `test`.`usuaris_backoffice_permisos` (`id`, `usuari_backoffice_id`, `es_admin`, `created_at`, `updated_at`) VALUES (NULL, '1', '0', '2011-10-06 00:00:00', '2011-10-06 00:00:00');
INSERT INTO `test`.`perfils` (`id`, `actiu`, `created_at`, `updated_at`) VALUES (NULL, '0', '2011-10-06 00:00:00', '2011-10-06 00:00:00');
INSERT INTO `test`.`perfils_usuari_backoffice` (`perfil_id`, `login`, `updated_at`) VALUES ('1', 'edgar', '2011-10-06 00:00:00');
INSERT INTO `test`.`widgets` (`id`, `classe`, `updated_at`) VALUES (NULL, 'hola', '2011-10-06 00:00:00');
INSERT INTO `test`.`widgets_usuari_backoffice` (`widget_id`, `usuari_backoffice_id`, `updated_at`) VALUES ('1', '1', '2011-10-06 00:00:00');

Code which returns the error is:

TRUNCATE usuaris_backoffice_permisos;
TRUNCATE perfils_usuari_backoffice;
TRUNCATE widgets_usuari_backoffice;
TRUNCATE usuaris_backoffice;

Thanks a lot for your time, hope someone can help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:59:42+00:00Added an answer on May 26, 2026 at 12:59 am

    Take a look http://dev.mysql.com/doc/refman/5.5/en/truncate-table.html. It says

    TRUNCATE TABLE fails for an InnoDB table if there are any FOREIGN KEY constraints from other tables that reference the table. Foreign key constraints between columns of the same table are allowed.

    From here it looks it worked in some previous versions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: In mysql I have a table which contains two
I have a problem with mysql query .. I have a table in the
I have problem in creating tinyint field in MySQL database using Hibernate. I used
I have this really weird problem with my MySQL table. After some time a
I have a problem inserting a row in a MySQL table when the table
I have a problem with my mysql insert statement. I have a form which
I have a problem with mysql connection. I have a php script which upload
basically i have this problem i have a table of posts(in my mysql database)
I have a mysql problem, my query looks as follows but not complete SELECT
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.