Open Source Tutorials - Open Source Training
Open source training & tutorials from experienced, passionate people
chrome icon firefox icon ie icon opera icon safari icon Sings in these Browsers
A- A A+

By A Web Design

Welcome, Guest
Username Password: Remember me

foreign key constraint failing
(1 viewing) (1) Guest
All your queries regarding
MySQL Installation,
Learning MySQL DBA,
and tonnes more... will be solved in this forum
  • Page:
  • 1
TOPIC:

foreign key constraint failing

foreign key constraint failing 1 year, 4 months ago #438

  • yoko
On executing the DELETE statement I keep getting the error about foreign key constraint failing. What do I do?

Re: foreign key constraint failing 1 year, 4 months ago #476

  • kuldeep
  • OFFLINE
  • Junior Boarder
  • Posts: 35
  • Karma: 0
What it means is that so of the data that you’re trying to delete is still alive in another table. Like if you have a table for universities and a table for students, which contains the ID of the university they go to, running a delete on a university table will fail if the students table still contains people enrolled at that university. Proper way to do it would be to delete the offending data first, and then delete the university in question. Quick way would involve running SET foreign_key_checks=0 before the DELETE command, and setting the parameter back to 1 after the DELETE is done. If your foreign key was formulated with ON DELETE CASCADE, the data in dependent tables will be removed automatically.
  • Page:
  • 1
Time to create page: 1.12 seconds
OSV Newsletter


Receive HTML?

NOTE: To prevent subscription to the OSV newsletter, uncheck the checkbox above.
Guest Blog for OSV
Free Ebook Download