简体   繁体   中英

FOREIGN KEY ON DELETE SET NULL

I am trying to create table but keep getting following error on last line at foreign key. Please help:

CREATE TABLE branch_supplier(
branch_id INT,
supplier_name VARCHAR(40),
supply_type VARCHAR(40),
PRIMARY KEY(branch_id, supplier_name),
FOREIGN KEY(branch_id)REFERENCES branch(branch_id) ON DELETE SET NULL
);

Failed

ER_FK_COLUMN_NOT_NULL: Column 'branch_id' cannot be NOT NULL: needed in a foreign key constraint 'branch_supplier_ibfk_1' SET NULL

Trying to create a new table in mysql and setting up foreign key.

A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL.

You define branch_id as nullable. But that is not allowed because it is part of the primary key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM