Add-Migration while explicit migrations are expected

So, I have the main problem associated with creating a transfer, when I do not have database synchronization (until the last migration there is no database at all) and have already made significant changes to my model.

These are the specific details:

  • Have a sequence of explicit migrations.
  • There is no database. In short, you have many pending changes.
  • Changes made to models / context.
  • When trying to add migration, he will complain that explicit migrations are waiting .
  • If I try to migrate (and bring my database in synchronization), either through Update-Database or migrate.exe, it will fail (after successful application of explicit migrations), and automatic migrations will not be enabled.
  • I don't want to enable automatic migration either (to prevent any circuit changes that need to be committed, and missing in the code.)

I understand that after the failure in No. 5, I can now start # 4. Then try again # 5 and voilΓ‘.

My question is: if this is the expected approach to solve this stupid situation.

+5
source share
2 answers

I would use the following approach.

First you need to apply the migration and specify the latter.

PM> Update-Database -TargetMigration AnyMigrationName # It updates database to a migration named "AnyMigrationName" # This will apply migrations if the target hasn't been applied or roll back migrations # if it has 

When your local database is updated, you simply add a new migration.

 PM> Add-Migration NewMigrationName # it scaffolds a new migration named "NewMigrationName" 

Looking for good help, I found these blog posts about EF Migrations that might help you. They cover a lot of questions and EF Migrations and Merge Conflict and the EF Migrations Command Reference in particular.

+10
source

this error is displayed if you have many pending migrations.

If you do not need existing migrations, first delete (exclude) all migration to the migration folder, and then add a new migration.

Add-Migration new

0
source

Source: https://habr.com/ru/post/1201919/


All Articles