示例二:
MySQL里创建外键时(Alter table xxx add constraint fk_xxx foreign key),提示错误,但只提示很简单的信息:ERROR 1005 (HY000): Can't create table '.\env_mon\#sql-698_6.frm' (errno: 150)。根本起不到解决问题的作用。
|
(以下红色部分为已经修改) drop table if exists products;
create table line_items( constraint fk_items_product foreign key (product_id) references producets(id), index(product_id) |
出现的报错:
| ERROR 1005: Can't create table |
主要问题以及解决办法是:
| 1,MySQL支持外键约束,并提供与其它DB相同的功能,但表类型必须为 InnoDB 2、建外键的表的那个列要加上index |

RSS订阅