• Register
0 votes
252 views

Problem :

In the MySQL I am trying to drop the table named bericht.
I tried many options however still facing the same error that my table cannot be dropped. I am facing following error message :

#1217 - Cannot delete or update a parent row: a foreign key constraint fails

Does anybody have any clue about this error #1217?

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Following approach will help you in resolving your issue :

SET FOREIGN_KEY_CHECKS=0; DROP TABLE bericht; SET FOREIGN_KEY_CHECKS=1;

The safest solution can be to delete the tables which are dependent on bericht table before deleting bericht. I will suggest you to use the bash and the method in mentioned above to drop all the tables in your database when you do not want to or can not delete or recreate the database itself.

The above mentioned error #1217 will occur only when the other tables are having the foreign key with the table you want to delete and if you want to use the InnoDB database engine. The above solution will temporarily disables the check on restraints and after that it will re enable them. Please make sure to delete foreign key restraints and the fields in tables which are depending on your bericht table, Else you may find your database in the broken state.

Further Readings :

https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_foreign_key_checks

9 7 4
38,600 points

Related questions

0 votes
1 answer 80 views
80 views
Problem : When I try to execute the below SQL command : INSERT INTO mytest_usershosts (RID,userid,hid,Usr,Pass) VALUES (NULL,1,1,"user","pass"); I am facing the below error message : ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f ... similar cases, but I am unable to find any solution. Is there anyone who have faced the same issue and knows the fix for the issue?
asked Dec 11, 2019 alecxe 7.5k points
0 votes
2 answers 1.1K views
1.1K views
Problem : I have created the tables in MySQL Workbench. But when I try to insert the values into the ORDRELINJE table i get below error: Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (srdjank.Ordrelinje, CONSTRAINT Ordrelinje_fk FOREIGN KEY ... (OrdreID)) I have seen many other posts on this topic but unable to fix my issue. How can I fix this issue?
asked Jan 24, 2020 jwilliam 3.9k points
0 votes
2 answers 294 views
294 views
Problem : I have created the tables in MySQL Workbench. But when want to insert values into my TBL ORDRELINJE table I face below error : Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (srdjank.TBLOrdrelinje, CONSTRAINT TBLOrdrelinje_fk FOREIGN KEY ... do the research on this topic, but no luck. Am I doing any mistake or someone have any idea about what can I do?
asked Dec 21, 2019 alecxe 7.5k points
0 votes
1 answer 24 views
24 views
Problem: I am unable to understand why a TRUNCATE on mygroup is not working? Even though I have it ON DELETE CASCADE SET I encounter below strange error: ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (mytest.instance, ...    DateTime     DATETIME DEFAULT NULL, FOREIGN KEY  (GroupID) REFERENCES mygroup(ID) ON DELETE CASCADE,    UNIQUE(GroupID) ) ENGINE=InnoDB;
asked Jul 23, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 272 views
272 views
I am facing this problems in many times and hardly getting the soluton. Can someone here help me to solve this issue?
asked Sep 14, 2020 Daniel Anderson 4k points
0 votes
1 answer 2.6K views
2.6K views
Problem : Following is my issue: I tried to install mysqlclient like below : C:\Users\alecxe>pip install mysqlclient Collecting mysqlclient Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1 cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz Installed ... beginner to this and would be very happy if any input as to how to go about fixing above error.
asked Dec 27, 2019 alecxe 7.5k points
0 votes
1 answer 38 views
38 views
Problem: I am able to create the table named employee which contains the column empid which is a computed column and empid column is the primary key also. It is the self referencing table and the column managerid references back to itself. But now if I try to save ... error my table is still working perfectly. I am trying to work in a table graphically not coding every time I make the change.
asked Jul 4, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 82 views
82 views
Problem : I am trying to import mySql database which was originally an access database into phpmyadmin and its giving me following error: incorrect table definition; there can be only one auto column and it must be defined as a key
asked Nov 14, 2019 peterlaw 6.9k points
0 votes
1 answer 8 views