Code: Select all
Database.SetInitializer<CustomerDbContext>(
new MigrateDatabaseToLatestVersion<CustomerDbContext, Configuration>());
Database.Initialize(false);
Code: Select all
public class Configuration : DbMigrationsConfiguration<CustomerDbContext>
{
public Configuration()
{
PgSqlConnectionInfo connectionInfo =
PgSqlConnectionInfo.CreateConnection(
"User Id=postgres;Password=postgres;Host=localhost;Port=5432;Database=etera;Schema=dev;");
TargetDatabase = connectionInfo;
SetSqlGenerator(connectionInfo.GetInvariantName(), new PgSqlEntityMigrationSqlGenerator());
}
}
Code: Select all
public class CreateBlogTable : DbMigration
{
public override void Up()
{
CreateTable(
"Blogs",
c => new
{
BlogId = c.Int(nullable: false, identity: true),
Name = c.String(unicode: false),
})
.PrimaryKey(t => t.BlogId);
}
public override void Down()
{
DropTable("Blogs");
}
}
Edit: It looks like that you have to create the DbMigration classes by using the Add-Migration command from NuGet to get the code executed.