Trying to add a foreign key constraint on a column that has null values

230 Views Asked by At

I was able to add foreign key constraints on a column when I first made the table, and I had created the column to accept null values.

But now that there is data in the table, actual records with null values, it seems I'm unable to add a foreign key constraint on one of the columns, because there are null values.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

This is kind of a pain, and it seems like I might just forego putting a foreign key back on this column.

0

There are 0 best solutions below