我有一个成功运行的初始迁移,但是,当我尝试添加一个新的迁移时,我被告知我不能,因为迁移正在等待:
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.
我可以在数据库__MigrationHistory
表中看到迁移:
SELECT [MigrationId] FROM [localacount].[dbo].[__MigrationHistory]
给出:
MigrationId
----------------------------------
201511051706498_InitialCreate
(1 row(s) affected)
这里发生了什么?为什么我不能添加下一次迁移?
答案 0 :(得分:1)
确保您定位正确的数据库并验证连接字符串。
在Update-Database
命令中,您已明确覆盖连接字符串,但尚未为Add-Migration
指定一个连接字符串。后者将使用您的上下文中的默认连接字符串 - 可能是一个不同的数据库。