Mysql,innodb - 无法创建外键

标签 mysql foreign-keys innodb

使用默认引擎 (MyIsam),我可以使用以下语法创建外键:

alter table `codes` add constraint foreign key(`associated_code_id`) references ask_codes(code_id)  on update cascade on delete cascade;

但是,当我使用 INNODB 创建表时,我无法再创建外键(mysql 给我错误 1005 (HY000): Can't create table 'my_table.#sql-3311_16115' (errno: 150) ))。

这是语法问题吗?感谢您的帮助,

最佳答案

您的问题是两列没有相同的类型 - 它们不完全匹配:

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.

关于Mysql,innodb - 无法创建外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10108426/

相关文章:

php - PHP 的 SSE 回显以随机间隔复制

Mysql:修剪数据库中的所有字段

php - 使用 Propel ORM 保存和检索 blob

SQL - 在具有不同列数的多列上创建外键

mysql - MyISAM 与 InnoDB

java - 插入到mysql,列数未定义

sql - 如果约束失败,则插入值或忽略行

mysql - 在 "Column Name"上创建外键时出错(检查数据类型)?

mysql - 我应该如何设置这些表来进行搜索?

MySQL Innodb 死锁 - 如何删除旧事件?