数据库添加外键错误:[Err] 1215 - Cannot add foreign key constraint 的解决
来源:互联网 发布:有肉的耽美网络剧 编辑:程序博客网 时间:2024/04/27 16:00
今天给mysql数据库中的表添加外键,保存时出现错误:[Err] 1215 - Cannot add foreign key constraint,导致无法添加外键。
外键定义添加的条件:
(1)外键对应的字段数据类型保持一致
(2)所有tables必须是InnoDB型,它们不能是临时表.因为在MySQL中只有InnoDB类型的表才支持外键(两张表的存储引擎一致)。
(3)设置外键时“删除时”设置为“SET NULL”
采用排除法,最后发现对应的数据类型不同,改正后即添加成功外键。
最后补充添加外键的语法,基本语法格式如下:
ALTER TABLE 数据表名 ADD CONSTRAINT 外键别名 FOREIGN KEY(字段1.1,字段1.2,...,字段1.n) REFERENCES 表名(字段2.1,字段2.2,...,字段2.n)
其中:
数据表名:要添加外键约束的数据表的名称。
外键别名:表示外键的代号。
字段1:表示子表中设置的外键。
表名:表示父表的名称。
字段2:表示父表的主键。
以上即为添加数据库外键的基本内容。
0 0
- 数据库添加外键错误:[Err] 1215 - Cannot add foreign key constraint 的解决
- MySQL中创建外键的错误:1215 Cannot add the foreign key constraint
- MySQL 不能添加外键:Cannot add foreign key constraint错误
- 无法添加外键约束的原因(cannot add foreign key constraint)
- MySQL 1215 Cannot add foreign key constraint 错误解决办法
- 1215-Cannot add foreign key constraint
- 1215 - Cannot add foreign key constraint
- 1215 - Cannot add foreign key constraint
- 1215 Cannot add the foreign key constraint
- 1215-Cannot add the foreign key constraint
- mysql无法添加外键约束(cannot add foreign key constraint)
- mysql无法添加外键约束(cannot add foreign key constraint)
- mysql中添加外键约束失败(cannot add foreign key constraint)
- Cannot add or update a child row: a foreign key constraint fails 无法添加外键
- Mysql出现 Cannot add foreign key constraint 错误
- Liquibase异常 mysql数据库 Cannot add foreign key constraint
- mysql添加外键失败:sql 1452 Cannot add or update a child row:a foreign key constraint fails
- [Mysql] 添加外键失败:Cannot add or update a child row:a foreign key constraint fails
- Sort函数
- mysql和pdo原生操作
- Swift Map方法
- Dos命令查看端口占用及关闭进程
- 在Linux中创建静态库.a和动态库.so
- 数据库添加外键错误:[Err] 1215 - Cannot add foreign key constraint 的解决
- jQuery_克隆和替换节点
- 使用Nexus搭建Maven私服
- 虚拟机模拟搭建VMware虚拟化平台
- C++11 raw strings literals tutorial
- IOCP 二进制协议 分包
- ——Character类、正则表达式、Math类、DateFormat类、
- 程序员为什么不适用一般的绩效考核
- 异常处理