EF 7 Migration to Existing Database

后端 未结 3 953
野趣味
野趣味 2021-02-06 00:11

I am working on a web project using ASP.Net 5 and EF7.

I have imported all the tables from existing database onto my models in my project. However, I am having problems

3条回答
  •  走了就别回头了
    2021-02-06 01:15

    If you are strongly believe, that new (EF7) database schema will match your old database schema (including index and key names) - you may run 'Initial' migration to empty (temporary) database and then copy __EFMigrationHistory table from there to your real database.

    Otherwise, I recommend you create empty database using migration and use sql insert into ... select commands to copy data from your old database. Without this, you will receive exceptions when upgrading database later - for example changing index will lead to DropIndex and CreateIndex migration commands, and DropIndex will fail because there is no index with this name (index exist with other, pre-EF7 name).

    In my projects - old (from EF6) and new database schemes are different, and I used second option.

提交回复
热议问题