The following questions have been updated: the link address is being designed for the mall data table. Currently, there is a commodity table goods, a commodity Attribute Table attributes, and a commodity and attribute Association Table goods_and_attributes :, the item table has been associated with the item attribute Association table. Now I...
The link address for subsequent issues has been updated.
I am working on the design of the mall data table. Currently, there is a commodity table.goods
, Item Attribute Tableattributes
, Item and attribute Association Tablegoods_and_attributes
:
The item table has been associated with the item attribute Association table. Now I wantgoods_and_attributes
Set foreign keyattribute_id
And item Attribute Tableattributes
When connected, the database reports an error:
I cleared the data and re-created the slq statement:
DROP TABLE IF EXISTS `goods_and_attribute`;CREATE TABLE `goods_and_attribute` ( `id` int(11) NOT NULL AUTO_INCREMENT, `goods_id` int(11) DEFAULT NULL, `value` varchar(50) NOT NULL, `stock` int(11) NOT NULL, `attribute_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `IDX_72C0A1A2B7683595` (`goods_id`), KEY `IDX_20160603` (`attribute_id`) USING BTREE, CONSTRAINT `FK_good_id_20160519` FOREIGN KEY (`goods_id`) REFERENCES `goods` (`id`) CONSTRAINT `FK_attribute_id_20160603` FOREIGN KEY (`attribute_id`) REFERENCES `attributes` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
The error message is as follows:
Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT `FK_attribute_id_20160519` FOREIGN KEY (`attribute_id`) REFERENCES `a' at line 1
If you can give me some suggestions, it will be of great help to me!
Reply content:
The link address for subsequent issues has been updated.
I am working on the design of the mall data table. Currently, there is a commodity table.goods
, Item Attribute Tableattributes
, Item and attribute Association Tablegoods_and_attributes
:
The item table has been associated with the item attribute Association table. Now I wantgoods_and_attributes
Set foreign keyattribute_id
And item Attribute Tableattributes
When connected, the database reports an error:
I cleared the data and re-created the slq statement:
DROP TABLE IF EXISTS `goods_and_attribute`;CREATE TABLE `goods_and_attribute` ( `id` int(11) NOT NULL AUTO_INCREMENT, `goods_id` int(11) DEFAULT NULL, `value` varchar(50) NOT NULL, `stock` int(11) NOT NULL, `attribute_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `IDX_72C0A1A2B7683595` (`goods_id`), KEY `IDX_20160603` (`attribute_id`) USING BTREE, CONSTRAINT `FK_good_id_20160519` FOREIGN KEY (`goods_id`) REFERENCES `goods` (`id`) CONSTRAINT `FK_attribute_id_20160603` FOREIGN KEY (`attribute_id`) REFERENCES `attributes` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
The error message is as follows:
Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT `FK_attribute_id_20160519` FOREIGN KEY (`attribute_id`) REFERENCES `a' at line 1
If you can give me some suggestions, it will be of great help to me!
Do not use physical Foreign keys of databases. Use programs to implement and maintain logical Foreign keys, especially in highly concurrent Internet environments.
Upstairs positive solution. It is unwise to make a physical foreign key.
I have never done any foreign keys in my projects. It makes no sense. There are still many unexpected effects. Generally, you just need to index a table. Not all situations are involved, in most cases, foreign keys are over-designed and unnecessary. Think about the design of the goods_and_attributes table. Of course, you have designed other tables as well ..., there are no creators and dates, and no status or deteled. It's too easy for you, like toys,