I'm a mysql beginner and I'm currently working on foreign keys. I would like to create three tables: users, items, orders and link them together
Users table:
CREATE TABLE users (
user_id INT(10) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
PRIMARY KEY(user_id)
);
Items table:
CREATE TABLE items (
item_id INT(10) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
PRIMARY KEY(item_id)
);
Orders table:
CREATE TABLE orders (
order_id INT(10) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
item_id INT,
quantity INT(10) NOT NULL,
user_id INT,
PRIMARY KEY (order_id),
FOREIGN KEY (item_id) REFERENCES items (item_id),
FOREIGN KEY (user_id) REFERENCES users (user_id)
);
But I got the error 1005: can't create table 'new.orders' (error:150)
What is wrong with my code?
Thanks!