My Seed()
method is never called. It is called when I do an Update-Database
from the Package Manager Console, but never when I run from code.
If I delete my database, all tables are created ( so my migration classes are executed), but my Seed() code is never called.
MVC 4, Entity Frame Work 5 Code First.
Global.asax:
protected void Application_Start()
{
Database.SetInitializer<MyContext>(new DbInitializer());
}
DBInit:
internal class DbInitializer : MigrateDatabaseToLatestVersion<MyContext, Migrations.Configuration>
{
}
DBContext:
public partial class MyContext : DbContext
{
public MyContext() : base("DefaultConnection")
{
}
// public DBSets....
}
Configuration:
internal sealed class Configuration : DbMigrationsConfiguration<MyContext>
{
public Configuration()
{
// The constructor is actually called
AutomaticMigrationsEnabled = false;
}
protected override void Seed(MyContext context)
{
// My seed code, never called
}
What could be wrong?