3
votes

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

2

2 Answers

4
votes

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

1
votes

Finally I could solve it, the problem was my azure DB tables didn't have identity property (autoincrement) so the table had a PK but it doesn't have their identity property.

What happen?

When I tried to import my local DB (which all its tables have the identity property) to azure DB I didn't by a unknown method (I used the task of SSMS: Task>Export Data...) This could import all the tables, PK Constraints and all the data but it didn't import all the identity properties.

How to fix it?

What I did to solve it was importing my database again but this time in a correct way: importing my local db to azure db by a bacpac file (azure database recognizes this kind of backup file).

Actually, before I used the method to import my DB that I used, I tried importing my db by importing bacpac file but I couldn't because I used SSMS 2014 and researching on another stackoverflow questions I figured out I can't make a bacpac file with SSMS 2014 (I had a problem with clustered Index) but I can do it with SSMS 2016, so I installed it and finally I could create the bacpac file and then I could import it to my azure db, and it had the identity property