none
Using dbmigrator with existing db error RRS feed

  • Question

  • Hi 

    I'm trying to using code first migrations with an existing db. I have something like the following in place:

      public class TestMigration : DbMigration
        {
            public override void Up()
            {
                CreateTable("TestMigrationTable", t => new { Id = t.Int(identity:true, nullable:false), Name = t.String(nullable:true)} );
            }


            public override void Down()
            {
                DropTable("TestMigrationTable");
            }
        }


        public class MigrateExecuter
        {
            public void UpdateToLatest()
            {
                var conf = new DbMigrationsConfiguration<local_FooEntities>();
                conf.MigrationsNamespace = "Foo.Migrations";
                
                var migrator = new DbMigrator(conf);


                migrator.Update();
            }
        }

    Calling UpdateToLatest() results in this error:

    System.NotSupportedException : Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.
       at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)

    Any suggestion on how to resolve this?

    Regards,

    Fredrik

    Thursday, March 22, 2012 9:24 PM

Answers

  • Hi vpalle,

    Welcome to MSDN Forum.

    Currently, migrations can only be used with Code First models, it doesn't support Database First and Model First.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 26, 2012 6:17 AM
    Moderator