Add Foreign Key to existing table(将外键添加到现有表)
问题描述
我想向名为katalog"的表添加外键.
当我尝试这样做时,我收到此错误消息:
<块引用>INNODB 状态错误:
<块引用>120405 14:02:57 表的外键约束错误mytable.#sql-7fb1_7d3a:
当我使用此查询时,它可以工作,但删除时"操作错误:
两个表都是 InnoDB 并且两个字段都是INT(11) not null".我正在使用 MySQL 5.1.61.尝试在 MacBook Pro 上使用 MySQL Workbench(最新)触发此 ALTER 查询.
表创建语句:
要将外键 (grade_id) 添加到现有表 (users),请按照以下步骤操作:
I want to add a Foreign Key to a table called "katalog".
When I try to do this, I get this error message:
Error in INNODB Status:
120405 14:02:57 Error in foreign key constraint of table mytable.#sql-7fb1_7d3a:
When i use this query it works, but with wrong "on delete" action:
Both tables are InnoDB and both fields are "INT(11) not null". I'm using MySQL 5.1.61. Trying to fire this ALTER Query with MySQL Workbench (newest) on a MacBook Pro.
Table Create Statements:
To add a foreign key (grade_id) to an existing table (users), follow the following steps:
这篇关于将外键添加到现有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!