Home >Database >navicat >Navicat adds foreign key error 1452

Navicat adds foreign key error 1452

(*-*)浩
(*-*)浩Original
2019-08-14 11:51:079136browse

Navicat adds foreign key error 1452

If you encounter this situation, there should be data in your table. It is because the attributes in the data do not correspond. (Recommended tutorial: navicat tutorial)

Navicat adds foreign key error 1452

The simplest and crudest way to solve this problem

Just delete all the data in the table and then create a foreign key;

If you can’t bear to delete it, find the non-corresponding attributes in the two tables. !

Prerequisites for creating foreign keys:

1: Whether the fields of the reference table exist.

2: The fields that make up the foreign key are required to be Index and foreign key fields are primary keys in other tables.

3: Both are innodb tables.

4: The field types are the same.

5: The syntax is correct

In order to establish a foreign key relationship between two MySQL tables, the following three conditions must be met:

* 两个表必须是InnoDB表类型。    
* 使用在外键关系的域(字段)必须为索引型(Index)。所以要为设置外键的字段建立index
* 使用在外键关系的两个域(字段)数据类型要相同。

The above is the detailed content of Navicat adds foreign key error 1452. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn