DbMigrations problem

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
teckerstorfer
Posts: 4
Joined: Thu 24 May 2012 05:52

DbMigrations problem

Post by teckerstorfer » Thu 24 May 2012 05:57

I have the following configuration (which is executed fine) - by using

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());
        }
        
    }
The problem is that the migration code is never executed:

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");
        }
    }
What do I have to do that this code gets executed and the database updated?

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.


Post Reply