Getting Initial Entity Framework Migrations Script

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 23:48:32

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!