我正在尝试将一个表连接到数据库中的两个不同表。我收到下一个错误:
错误代码:1005。无法创建表 project
. orders
(错误号:150“外键约束格式不正确”)0.625秒
要连接的表是:
CREATE TABLE IF NOT EXISTS ORDERS
(
ORDER_ID INT NOT NULL UNIQUE auto_increment,
PRICE INT NOT NULL,
ORDERED_DATA timestamp default now(),
clients_ID INT,
product_second_ID int,
PRIMARY KEY(ORDER_ID),
INDEX `fk_orders_clients1_idx` (`clients_ID` ASC),
INDEX `fk_orders_product_second1_idx` (`product_second_ID` ASC),
CONSTRAINT `fk_orders_clients1`
FOREIGN KEY (`clients_ID`)
REFERENCES `schooldb`.`clients` (`ID`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_orders_product_second1`
FOREIGN KEY (`product_second_ID`)
REFERENCES `schooldb`.`product_second` (`ID`)
ON DELETE CASCADE
ON UPDATE CASCADE
);
将连接的其他两个表:
CREATE TABLE IF NOT EXISTS Product_SECOND (
ID INT NOT NULL unique auto_increment,
NUME CHAR(24) not NULL,
STOCK INT,
RESTOCKED timestamp default now() on update now(),
ADDED timestamp default now(),
PRIMARY KEY(ID)
);
CREATE TABLE IF NOT EXISTS CLIENTS
(
ID int NOT NULL unique auto_increment,
NUME CHAR(24) NOT NULL,
PRENUME CHAR(24) NOT NULL,
EMAIL CHAR(24),
PASSWORD_user CHAR(10) NOT NULL,
PHONE INT,
ADDRESS CHAR(50) NOT NULL,
DATE_CREATE_ACCOUNT timestamp default now(),
DATE_OF_LAST_ORDER timestamp default now() on update now(),
PRIMARY KEY(ID)
);
暂无答案!
目前还没有任何答案,快来回答吧!