The reason why mysql cannot add foreign keys appears
1. The data type and data length of the associated columns of the two tables are inconsistent.
For example, vARCHAR (20) is in column A of Table A, and VARCHAR (25) is in column B of table B. In this way, A and B cannot form foreign key association relationship.
2, when creating tables, add ENGINE=InnoDB DEFAULT CHARSET= UTf8;
CREATE TABLE `A` (
1. The data type and data length of the associated columns of the two tables are inconsistent.
For example, vARCHAR (20) is in column A of Table A, and VARCHAR (25) is in column B of table B. In this way, A and B cannot form foreign key association relationship.
2, when creating tables, add ENGINE=InnoDB DEFAULT CHARSET= UTf8;
CREATE TABLE `A` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
In this way, if the B table and A table to be associated with the foreign key, then create B table also add ENGINE=InnoDB DEFAULT CHARSET= UTf8;
Read More:
- MySQL failed to add foreign key: SQL 1452 cannot add or update a child row:a foreign key constraint fails
- Mysql error 1452 – Cannot add or update a child row: a foreign key constraint fails
- 1822 – Failed to add the foreign key constraint. Missing index for constraint ‘tb_emp_ibfk_1’ in the
- Solution to error 1452: cannot add or update a child row: a foreign key constraint failures in MySQL
- Failed to add the foreign key constraint. Missing index for constraint ‘stu_ibfk_1’ in the reference
- Mysql error when deleting the table structure: Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint fails
- MYSQL ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
- MySQL failed to add foreign key error 1452
- MySQL:Foreign key fails with error Error Code: 1452.
- MySQL error 1451 23000 foreign key exception handling
- MySQL error code 1217 (ER_ROW_IS_REFERENCED): Cannot delete or update a parent row: a foreign key co
- Ora-02292: integrity constraint (XX) violated – child record found foreign key Association, record cannot be deleted
- mysql Error Code: 1022. Can’t write; duplicate key in table `xxx`
- greendao insert data UNIQUE constraint failed: PURCHASE_ORDER_TABLE._id (code 1555)
- [reprint and save] MySQL does not set the primary key and uses the self growing ID method
- MySQL skip grant tables add user error 1290
- MySQL Workbench: Error Code: 2013. Lost connection to MySQL server during query solution
- Txt import MySQL: error 1062 (23000): duplicate entry ‘0’ for key ‘primary’
- Solution of duplicate entry ‘value’ for key ‘field name’ in MySQL
- Serverlet: How to Add, Delete, Modify and Query item code