Sql database debug, please help.

create database project_db;

USE project_db;

CREATE TABLE customers ( customer_id INT NOT NULL AUTO_INCREMENT, f_name VARCHAR(255) NOT NULL, l_name VARCHAR(255) NOT NULL, phone_no INT NOT NULL, email VARCHAR(255), post_code VARCHAR(255) NOT NULL, city VARCHAR(255) NOT NULL, state VARCHAR(4) NOT NULL, PRIMARY KEY (customer_id)
);

CREATE TABLE orders ( customer_id int not null, order_no INT NOT NULL AUTO_INCREMENT, product_id varchar(255) not null, post_code varchar (255) not null, city varchar(255) not null, state varchar(4) not null,

primary key (order_no), FOREIGN KEY (customer_id) REFERENCES customers(customer_id), FOREIGN KEY (post_code) REFERENCES customers(post_code), FOREIGN KEY (city) REFERENCES customers(city), FOREIGN KEY (state) REFERENCES customers(state), FOREIGN KEY (product_id) REFERENCES products(product_id)); 

CREATE TABLE products ( product_id INT NOT NULL AUTO_INCREMENT, stock_quantity INT NOT NULL, product_name VARCHAR (255) NOT NULL, price Decimal (13, 2) NOT NULL, PRIMARY KEY (product_id) );

The orders table doesn't work due to an error code (1822). Failed to add the foreign key constraint. Missing index for constraint 'orders_ibfk_2' in the referenced table 'customers'

Does anyone know what's wrong with the code iv been stuck on this for like 2 days. Thanks.

submitted by /u/yoloriverswag77
[link] [comments]

from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/ZJCKtcU

Leave a comment

Design a site like this with WordPress.com
Get started
search previous next tag category expand menu location phone mail time cart zoom edit close