C# – Cannot insert the value NULL into column, table; Column does not allow nulls… But this column is Primary Key and has autoincrement property

asp.net-mvcazurecsql server

I have published a web app, it's running on azure. The web app project I was testing on my computer (localhost) and then on the web app. When I tested to create a new row a data (for example a new person on a PersonTable) It worked on my localhost but when I tested the web app published it throws this error:

Cannot insert the value NULL into column 'ID_ANTEC_PERS', table
'Telejdb.dbo.ANTECEDENTES_PERSONALES'; column does not allow nulls.
INSERT fails. The statement has been terminated.

That column (ID_ANTEC_PERS) is the ID of that table(ANTECEDENTES_PERSONALES), but I set to this column the identity(1,1) property on my sql server DB. When I worked this project in my computer (localhost) I hadn't this problems, I think it is because the project knew the sequence of that auto increment property. But now, once the web app is published and running on azure, I wanted to see the code of my project but I realized it was compiled on .dll files So I can't edit the web app project. Any Help? Guide? Suggestions? I will appreciate that.

Thanks in advance

Best Answer

Check the field from your table design then Check the checkbox from your table design then it allows to insert null value in table

id is supposed to be an incrementing value.

You need to set this, or else if you have a non-nullable column, with no default value, if you provide no value it will error.

To set up auto-increment in SQL Server Management Studio:

Open your table in Design
Select your column and go to Column Properties
Under Indentity Specification, set (Is Identity)=Yes and Indentity Increment=1

in local if you are not getting this problem means you have to update the

azure database

Related Topic