Skip to content
Advertisement

Getting Error While Setting The data to Sql Db, Saying Cannot set the Value of Created at with Null

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement