ca9163d9
ca9163d9

Reputation: 29227

How to restart/merge migration?

I'm using Entity framework code first and I have almost 10 migrations now. I found a design issue and some of the DBMigrations are not what I expected and I want to re-generated the database.

  1. How to discard all these existed migrations and regenerate the tables on development database? (delete all the cs files under Migrations folder and delete the database? What if I want to keep the first xxxxxx_InitialCreate.cs and restart from there?)
  2. What if the database already published to production database server? What's the best way to sync the development database/migrations and production database/migrations?

Upvotes: 0

Views: 137

Answers (1)

Gecko
Gecko

Reputation: 1344

You could revert to that initial migration

Update-Database [-SourceMigration <String>] [-TargetMigration <String>]
  [-Script] [-Force] [-ProjectName <String>] [-StartUpProjectName <String>]
  [-ConfigurationTypeName <String>] -ConnectionString <String>
  -ConnectionProviderName <String> [<CommonParameters>]

is the Syntax so:

Update-Database -TargetMigration InitialCreate

reverts your database to the initial migrationFor the second part I would just change the connection string to the production database and run the migration again. No loss of data should occur.

Upvotes: 1

Related Questions