--source include/have_innodb.inc CREATE TABLE parent ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)) ENGINE = InnoDB; insert into parent values(1); CREATE TABLE child ( id INT NOT NULL AUTO_INCREMENT, parent_fk INT DEFAULT NULL, PRIMARY KEY (id), CONSTRAINT fk_child_parent FOREIGN KEY (parent_fk) REFERENCES parent (id)) ENGINE = InnoDB; INSERT INTO child values (1, NULL); --error 1452 INSERT INTO child values (2, 0); INSERT INTO child values (3, 1); select * from child; ALTER TABLE child MODIFY COLUMN parent_fk INT NOT NULL; select * from child;