0
votes

I am using code first to generate a database. I want the database to create from a migration generated using add-migration InitialCreate

The database does indeed create using the code from the InitialCreate migration.

However when I try and create a subsequent migration using Add-Migration One

I get an error

Unable to generate an explicit migration because the following explicit migrations are pending: [201310112018474_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

I tried running Update-Database -Targetmigration:0 and it lists migrations that were created in the past but are no longer present.

PM> Update-Database -Targetmigration:0 Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Reverting migrations: [201310110726212_two, 201310110719552_InitialSchema, 201310090149561_k1]. Reverting automatic migration: 201310110726212_two. Reverting automatic migration: 201310110719552_InitialSchema. Reverting automatic migration: 201310090149561_k1.

The Migration History table only contains one record for the initial create. My question is, how does PM know about these old migrations that no longer exist?

Note - I have deleted the migrations from the migrations folder

I am using EF5, C# Winforms

1

1 Answers

0
votes

There is migrations folder in your solution that PM uses.

If you delete the migrations folder from you solution and run the application the database will be correctly created from the code.

You only need the migrations files if you have an existing database that needs migrations due to changes you've made in the code (and therefore the database needs to reflect this changes)