Using MySQL Workbench, I get an error:
Error code 1005: Cannot create table (errno 121) for the following
CREATE TABLE `addresses` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`order_id` int(10) unsigned NOT NULL,
`street_1` varchar(64) NOT NULL,
`street_2` varchar(64) DEFAULT NULL,
`city` varchar(64) NOT NULL,
`us_state` enum('AK','AZ','AR','CA','CO','CT','DE','DC','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY') NOT NULL,
`zip` varchar(16) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_order_id` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON UPDATE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
If I remove the foreign key constraint named FK_order_id, the table will be created. The foreign key is to a table created as follows:
CREATE TABLE `orders` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`customer_id` int(10) unsigned DEFAULT NULL,
`placed` timestamp NULL DEFAULT NULL,
`shipped` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_customer_id` (`customer_id`),
CONSTRAINT `FK_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
I do not understand the error I'm getting when trying to create address with the foreign key constraint.
Please advise!
Error code 1005: Cannot create table (errno 121) for the following
CREATE TABLE `addresses` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`order_id` int(10) unsigned NOT NULL,
`street_1` varchar(64) NOT NULL,
`street_2` varchar(64) DEFAULT NULL,
`city` varchar(64) NOT NULL,
`us_state` enum('AK','AZ','AR','CA','CO','CT','DE','DC','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY') NOT NULL,
`zip` varchar(16) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_order_id` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON UPDATE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
If I remove the foreign key constraint named FK_order_id, the table will be created. The foreign key is to a table created as follows:
CREATE TABLE `orders` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`customer_id` int(10) unsigned DEFAULT NULL,
`placed` timestamp NULL DEFAULT NULL,
`shipped` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_customer_id` (`customer_id`),
CONSTRAINT `FK_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
I do not understand the error I'm getting when trying to create address with the foreign key constraint.
Please advise!