SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

It just simply means that the value for column country on table comments you are inserting doesn't exist on table country_type or you are not inserting value for country on table user. Bear in mind that the values of column country on table comments is dependent on the values of ID on table country_type.


You have foreign keys between this table and another table and that new row would violate that constraint.

You should be able to see the constraint if you run show create table user, it shows up as CONSTRAINT... and it shows what columns reference what tables/columns.

In this case country references country_type (id) and you are not specifying the value of country. You need to put a value that exists in country_type.

Tags:

Mysql

Sql