views:

70

answers:

1

When I'm trying to create a foreign key linked to a primary key in another table I get:

#1452 - Cannot add or update a child row: a foreign key constraint fails
(`fayer`.`#sql-225c_1d3`, CONSTRAINT `#sql-225c_1d3_ibfk_1` FOREIGN KEY (`country_id`)
REFERENCES `countries` (`id`) ON DELETE CASCADE)

I have checked that all tables are using innodb and the datatype are both "int".

What is the problem?

+1  A: 

You have rows that violate the constraint you're trying to add.

In this particular case, there are values in your country_id column that do not exist in id column of countries table.

ChssPly76
i have edited so the value in country_id exists in id. but it still doesnt work.
ajsie
Does it still give you the **same** error as above even after `OMG Ponies` ' query returns no rows? Seems unlikely - if that's the case, there must be something else in play.
ChssPly76