Unable to add migration

.net entity-framework entity-framework-6

Question

I have an initial migration which has run successfully, however, when I try to add a new one I'm told I cant because the migration is pending:

PM> Update-Database -TargetMigration 201511051706498_InitialCreate -ConfigurationTypeName MyConfiguration -ConnectionString "__My_Connection_String__"
cmdlet Update-Database at command pipeline position 1
Supply values for the following parameters:
ConnectionProviderName: System.Data.SqlClient
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201511051706498_InitialCreate].
Applying explicit migration: 201511051706498_InitialCreate.

PM> Add-Migration -ConfigurationTypeName MyConfiguration
cmdlet Add-Migration at command pipeline position 1
Supply values for the following parameters:
Name: InitialCorrectLedgeringColumns
Unable to generate an explicit migration because the following explicit migrations are pending: [201511051706498_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

I can see the migration in the database __MigrationHistory table:

SELECT [MigrationId] FROM [localacount].[dbo].[__MigrationHistory]

Gives:

MigrationId
----------------------------------
201511051706498_InitialCreate

(1 row(s) affected)

What's going on here? Why can't I add the next migration?

1
1
11/5/2015 6:27:00 PM

Accepted Answer

Make sure you're targeting the right database and verify your connection string.

In your Update-Database command you have explicitly overridden the connection string, but haven't specified one for Add-Migration. The latter would then be using the default connection string from your context - presumably a different database.

1
11/5/2015 6:36:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow