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()

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


    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?



    Thursday, March 22, 2012 9:24 PM


  • 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

    • Marked as answer by Allen_MSDN Thursday, March 29, 2012 1:22 AM
    Monday, March 26, 2012 6:17 AM