josephj1989
josephj1989

Reputation: 9709

EF5 Code first migrations reset migrations

I was using EF5 code first and migrations right from the start.But I messed up something and decided to reset my migrations.

I did enable-migrations -force

Then tried add-migrations xyz

I expected only to see incremental changes (addition of 2 tables) Instead it tries to recreate every table.I dont want this to happen as it is shared via GIT and I need to push the migration also.

I have deleted all migration history and folder.What I want is a way to do another migration and it should only do the incremental create tables as other tables are already there

Upvotes: 1

Views: 679

Answers (1)

Anders Abel
Anders Abel

Reputation: 69250

You need to do this in two steps:

  1. Comment out your added tables and create an empty migration that updates the meta data to the state before those where added, by using the -ignore-changes switch (see my command reference)
  2. Readd your tables and create a migration. Now it should contain only those two new tables.

Please note that whenever you mess manually with the migrations you need to be careful with the state of the metadata or you can get really nasty surprises.

Upvotes: 2

Related Questions