MySQL 建立外來鍵報錯Can't write; duplicate key in table

feelpurple發表於2017-09-03
mysql> create table orders2(id int auto_increment primary key, customer_id int, description varchar(50), constraint fk_orders foreign key (customer_id) references customer(id));
ERROR 1105 (HY000): Can't write; duplicate key in table 'orders2'

報錯原因:
外來鍵名稱已經存在,更換一個外來鍵名稱
mysql> create table orders2(id int auto_increment primary key, customer_id int, description varchar(50), constraint fk_orders2 foreign key (customer_id) references customer2(id));
Query OK, 0 rows affected (0.22 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2144449/,如需轉載,請註明出處,否則將追究法律責任。

相關文章