Problem Description:
After the migration file is generated, the migration is performed, and the following error occurs:
django.db.utils.OperationalError: (3780,Referencing column ‘category_id’ and referenced column ‘id’ in foreign key constraint ‘tb_goods_visit_category_id_b3e36237_fk_tb_goods_category_id’ are incompatible.)
Question translation:
In the foreign key constraint ‘tb_goods_visit_category_id_b3e36237_fk_tb_goods_category_id’, the reference column ‘category_id’ and the reference column ‘ID’ are incompatible.
Cause analysis:
It is as like as two peas, which are inconsistent with the two data types. For example, varchar and int, or int, unsigned and int are not allowed.
My error is reported because the “category_id” in table a is bigint and the “Id” in table B is int. they are inconsistent.
Solution:
Modify the types of the related two columns in the associated two tables to be consistent, then you can add foreign keys, and then migrate the data successfully.
Similar Posts:
- MySQL ERROR 1005: Can’t create table (errno: 150) [How to Solve]
- [Solved] MYSQL Error: Cannot delete or update a parent row: a foreign key constraint fails
- [Solved] MYSQL Error when deleting a table: Cannot delete or update a parent row: a foreign key constraint fails
- ORA-02292: integrity constraint
- [Solved] Object references an unsaved transient instance – save the transient instance before flushing
- [Solved] MySQL uses the workbench tool, and the table status is read only
- [Solved] Oracle :value too large for column “SCHEMA”.”TABLE”.”COLUMN” (actual: 519, maximum: 500)
- MySQL Error Number 1005 Can’t create table (Errno:150)
- [Solved] Eclipse project red exclamation mark: build path problem
- Thinkphp6 Error: constraint violation: 1052 Column ‘id’ in where clause is ambiguous