Current follow-up issues, have been updated, link addresses
I am doing the design of the mall data table, currently has a commodity table goods
, commodity attribute table attributes
, commodity and Attribute Association table goods_and_attributes
:
, the commodity table has been linked with the Commodity Attribute Association table, now I want to set the foreign key in the Commodity Attribute Association table goods_and_attributes
attribute_id
and the commodity attribute table attributes
, the database will error:
I emptied the data and recreated 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 advice, it is a great help to me!
Reply content:
Current follow-up issues, have been updated, link addresses
I am doing the design of the mall data table, currently has a commodity table goods
, commodity attribute table attributes
, commodity and Attribute Association table goods_and_attributes
:
, the commodity table has been linked with the Commodity Attribute Association table, now I want to set the foreign key in the Commodity Attribute Association table goods_and_attributes
attribute_id
and the commodity attribute table attributes
, the database will error:
I emptied the data and recreated 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 advice, it is a great help to me!
Do not use the physical foreign keys of the database to implement and maintain logical foreign keys, especially in high-concurrency Internet environments.
Upstairs. Being a physical foreign key is a very unwise choice.
I have done the project has never done foreign key, this thing no meaning ah, there are many unexpected effects, the general table do point index on the line, not all the situation has, foreign key in most cases, the basic is over-design, there is no need. Think about it. Goods_and_attributes the design of this watch is more realistic, of course, your other table design also ... , creator and date, and status or deteled, you're too simple, like a toy,