mysql建立外键报错(error 150)

来源:互联网 发布:js 工作台布局 编辑:程序博客网 时间:2024/06/06 01:09

查看详细错误:Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.

1.被关联表中的字段不是索引(需要建立索引)


alter table `table-name` add constraint `key-name` foreign key `colume-name` references `table-name1`(`colume-name1`) on update cascade on delete cascade;