Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot insert the value NULL into column 'id', table 'XXX'; column does not allow nulls. INSERT fails

Tags:

sql

I am getting an insert error:

Cannot insert the value NULL into column 'id', table 'db.dbo.table'; column does not allow nulls. INSERT fails

.

I have checked the data and the column I am inserting into 'id' does not have any nulls. Any suggestions?

like image 292
Peter Sun Avatar asked Oct 31 '25 16:10

Peter Sun


1 Answers

The error

column does not allow nulls

is happening because you are trying to insert data which has NULL for the column id, for at least one record which you are trying to insert. It has nothing to do with the state of the column before you attempted the insert. Check the source of your insertion data and remove/replace the NULL values, or alter the id column to accept NULL.

like image 85
Tim Biegeleisen Avatar answered Nov 02 '25 06:11

Tim Biegeleisen