Cannot add or update a child row: a foreign key constraint fails

Reason one:

  The data type size, attributes (default value) of the foreign key field, or whether the database engine is InnoDB, and whether the encoding is consistent. (Foreign keys must be consistent)

View engine: show create table table name;

Cause 2:

  Whether the data is inserted in the two tables, if the data is inserted, check whether the data in the foreign key field is wrong.

If the foreign key field in table A is the primary key field in table B, check whether the data in the foreign key field in table A meets the requirements for the primary key in table B.

Guess you like

Origin www.cnblogs.com/Zeng02/p/12672761.html