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

Hello!
My name’s Eduardo and i’m reading the book “Build Your Own Database Driven
Website using PHP & MySQL”.
Well, actually, i’m reading the sample, but anyway, i’m doing a mysq database and I made some tables and filled in some information just fo testing, but when I try to delete the data from the tables,or when I try tdrop the tables, nothing happens, and I get the following message:“#1217 -
Cannot delete or update a parent row: a foreign key constraint fails”. Could
somebody tell me what does this means?
Thank you

It means that you are trying to cancel a row from one table, that contains a value present in at least one row in another table, and the foreign key constraint is there to avoid this from happening.

For example, let’s say you have a user table and a usertype table:

USER
UserId UserName UserTypeId
1 Joe 1

USERTYPE
UserTypeId Description
1 Administator
2 User

If UserTypeId is a foreign key for the USER table, pointing to the UserTypeId of the USERTYPE table, then right now you can’t delete the row with UserTypeId 1 in the USERTYPE table. This prevents you from deleting usertypes that are still used for some users.

You should first delete all the users with UserType 1, before you can delete the UserType itself.

If this isn’t clear, then you can read the manual:
http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

thank you very much guido 2004!