Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 19: 'NOT NULL constraint failed: Departments.CreatedAt'.


# TimeStamps

TimeStamps' behavior sets automatically the CreatedAt and UpdatedAt DateTime properties from an Entity when saving on EntityFramework.

// arrange
var post = new Post();

// act

// assert

// Post: 
//  CreatedAt: 2021-12-29T15:45:44.8259326+01:00
//  UpdatedAt: 2021-12-29T15:45:44.8261866+01:00
//  Id: 1

# Adding Into Your Project

# Register

Add AddTimeStamps into your ConfigureServices:

public void ConfigureServices(IServiceCollection services)
        // ... other services

# Decorate Your Entities

Decorate with ITimeStamps the Entities you want to have time stamps:

public class Post : Entity, ITimeStamped
    public string Title { get; set; }
    public DateTime CreatedAt { get; set; }
    public DateTime UpdatedAt { get; set; }

# Migration For New Columns

If you are creating a new table, you can use WithTimeStamps():

miru make.migration CreateProducts
public class CreateProducts : AutoReversingMigration
    public override void Up()

If your tables already exists, you can create a migration to alter the table adding the new columns:

miru make.migration AlterProductsAddTimeStamps
public class AlterProductsAddTimeStamps : Migration
    public override void Up()

    public override void Down()