having an issue getting this to work. MySQL keeps throwing the following:
ERROR 1064 (42000): 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 'ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (order_id) REFERENCES order' at line 6
And the SQL is:
DROP TABLE IF EXISTS `user_orders`;
CREATE TABLE `user_orders` (
`user_orders_user_id` int(10) unsigned NOT NULL default '0',
`user_orders_order_id` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`user_orders_user_id`, `user_orders_order_id`),
FOREIGN KEY (user_id) REFERENCES user(id),
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (order_id) REFERENCES order(id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
user_orders acts as an intermediate table for User.id and Order.id (i.e. holds a record for each order made by a user). I feel like I’m missing something obvious. The User table has no FK’s and the Order table has an FK (user_id) to User.id (with ON DELETE CASCADE ON UPDATE CASCADE).
Hopefully I’m just tired and it’s a minor syntax issue…
You have a comma that should not be there on this line:
Besides, in your table you have not field such as
user_idandorder_id. Infact you haveuser_orders_user_idanduser_orders_order_idBesides, you have to include the
orderbetween the'because is a reserved word as suggested by ypercube.