Seed method not called, Entity Framework 6

The only way I could get this to work was to call the seed method myself

Here are the methods for my DatabaseContext class

 public DatabaseContext() : base("DatabaseContext")
 {
    InitializeDatabase();
 }

 public DatabaseContext(string connectionString) : base(connectionString)
 {
     Database.Connection.ConnectionString = connectionString;
     InitializeDatabase();
 }

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
 }

Here I changed my InitializeDatabase method from

private void InitializeDatabase()
{
    Database.SetInitializer(new DatabaseInitializer());
    if (!Database.Exists())
    {
        Database.Initialize(true);
    }            
}

to

protected virtual void InitializeDatabase()
{
    if (!Database.Exists())
    {
        Database.Initialize(true);
        new DatabaseInitializer().Seed(this);
    }            
}

You need to call Update-Database from the Package Manager Console.


This can happen if your Update-Database command does not run successfully, and this does not necessarily mean that it errors out. There might be changes that EF recognizes as "outstanding" that need to be added to a migration.

Try calling "Add-Migration {migrationNameHere}" and then try "Update-Database" again.