在 MySQL 中创建表“ShoppingCart" - 错误 1005 [英] Creating table 'ShoppingCart' in MySQL - error 1005
本文介绍了在 MySQL 中创建表“ShoppingCart" - 错误 1005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 MySQL 中创建了一个名为ShoppingCart"的表,但显示错误 1005.这里有什么错误?
I've created a table in MySQL named 'ShoppingCart', but it shows error 1005. What's the mistake here?
mysql> create table ShoppingCart(
-> Current_Purchases varchar(100),
-> Previous_Purchases varchar(100),
-> Phone_No int(20),
-> constraint fk_shop foreign key (Phone_No) references Registration(Phone_No));
ERROR 1005 (HY000): Can't create table 'infoproject.shoppingcart' (errno: 150)
另一个表 'Registration' 已经创建并且存在相同数据类型的相同列.
The other table 'Registration' is already created and the same column is present with the same datatype.
推荐答案
外键引用的列必须是唯一的.在您的情况下,错误似乎是由 Registration
中的非唯一 Phone_No
引起的.更改Registration
表以在Phone_No
上添加唯一索引.
The column referenced by a foreign key has to be unique. In your case, it seems like the error is due to a non-unique Phone_No
in Registration
. Alter the Registration
table to add a unique index on Phone_No
.
这篇关于在 MySQL 中创建表“ShoppingCart" - 错误 1005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文