Getting Initial Entity Framework Migrations Script

前端 未结 1 818
一个人的身影
一个人的身影 2021-02-04 11:28

I just installed Entity Framework Migrations, added a property to a class, and gave EF Migrations a whirl.

My development database was promptly updated. So far, so good

相关标签:
1条回答
  • 2021-02-04 12:12

    The right way to start using EF migrations with an existing database is to start with adding an empty migration that contains the metadata of the current database.

    I think that you have to roll back to a model that is compatible with the initial database schema. Then run the following command:

    add-migration InitialSchema -IgnoreChanges
    

    That should give you an initial migration, that does nothing, but contains the metadata of the current model. You can of course add migrations later with -IgnoreChanges if you've expanded your code model to cover more of the tables already present in the database.

    Once you have that initial migration step in place, the scripting would work.

    Generally I would not recommend to use automatic migrations unless you only ever intend to only use automatic migrations. If you want some kind of control over the changes to the database (including scripting them) then code-based migrations is the way.

    0 讨论(0)
提交回复
热议问题