How to re-create initial migration on the same .cs file

后端 未结 4 1005
予麋鹿
予麋鹿 2021-02-13 23:29

As common in EF Code First I\'ve generated an \"Initial Create\" migration file where is located an outdated model of my db (I\'m developing the app so the model is still changi

相关标签:
4条回答
  • 2021-02-14 00:03

    My Project is Solved.
    Run in Package Manager Console:

    1. Drop-Database
    2. Remove-Migration
    3. Add-Migration InitialCreate
    4. update-database
    0 讨论(0)
  • 2021-02-14 00:05

    Here you can see how I solved this.

    Be careful with this approach because in my scenario I'm still in development phase so I do not need to keep the database nor the data.

    If you want to overwrite the current "InitialCreate" file and re-generate the DB, follow these steps:

    1) Run in Package Manager Console:

    Add-Migration InitialCreate -force

    2) Delete the physical database (use SSMS, T-SQL or your prefered)

    3) Run in Package Manager Console:

    Update-Database -TargetMigration:0 | update-database -force | update-database -force

    If you do not care about the current "InitialCreate" file itself, want to create a new one and re-generate the DB, follow these steps:

    1) Delete current "InitialCreate" .cs file

    3) Run in Package Manager Console:

    Add-Migration InitialCreate

    4) Delete the physical database (use SSMS, T-SQL or your prefered)

    4) Run in Package Manager Console:

    Update-Database -TargetMigration:0 | update-database -force | update-database -force

    0 讨论(0)
  • 2021-02-14 00:14

    Just delete the initial migration files from the 'Migrations' folder and retry.

    0 讨论(0)
  • 2021-02-14 00:17

    Try updating your database by writing Update-Database in Package Manager Console instead.

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