-1

I am Creating a table in SSMS with the Columns required for the Table and also with the Entitydata mandatory fields Like Id, CreatedAt, UpdatedAt, Version, Deleted.

And while setting the data through my application I am having Issue Like:

Cannot set CreatedAt Field as Null.

I am Getting this Issue if I am giving CreatedAt a hardcoded value as well:

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

I expected that it should not throw any exception and set the value to the database.

Andrea
  • 11,801
  • 17
  • 65
  • 72
Amitesh
  • 3
  • 1
  • 5
  • 1
    How can you expect it not to throw an error, check the table design it will have the not null property for that column. If you want to insert nulls then you have to change the table structure. The error is clear. – Ajan Balakumaran Oct 24 '19 at 12:05
  • Already Checked that the Field is set to accept the null Values in the database and that is the reason I am also Shocked , Why it is happening! – Amitesh Oct 24 '19 at 12:15

1 Answers1

0

In Order to fix this issue while creating the Database only, Give the default value of CreatedAt and UpdatedAt as CURRENT_TIMESTAMP. In the Design Window of the SQL Server set the Default field as CURRENT_TIMESTAMP.

Amitesh
  • 3
  • 1
  • 5