我们正在使用(的LocalDB)\ 11.0(Vstudio 2012)与EF5代码优先迁移和一切迄今很好的工作。无法产生明确的迁移(EF5)(迁移待定)
不过 - 今天我需要上几桌的创建几个指标,并遇到了问题。
首先,我做这点:
PM> add-migration AddIdxToOutage
Scaffolding migration 'AddIdxToOutage'.
我修改了代码的脚手架迁移到:
public override void Up()
{
Sql(@"CREATE NONCLUSTERED INDEX [idx_WtgId_StartDateTime_EndDateTime] ON [dbo].[Outages]
(
[WtgId] ASC,
[StartDateTime] ASC,
[EndDateTime] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");
}
我更新了数据库,结果是这样的:
PM> update-database -startupprojectname D3A.Data -force -verbose
Using StartUp project 'D3A.Data'.
Using NuGet project 'D3A.Data'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'D3A.Data.StorageContext' (DataSource: (localdb)\v11.0, Provider: System.Data.SqlClient, Origin: Convention).
Applying code-based migrations: [201310301258520_AddIdxToOutage].
Applying code-based migration: 201310301258520_AddIdxToOutage.
CREATE NONCLUSTERED INDEX [idx_WtgId_StartDateTime_EndDateTime] ON [dbo].[Outages]
(
[WtgId] ASC,
[StartDateTime] ASC,
[EndDateTime] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
[Inserting migration history record]
Running Seed method.
idx创建在桌面上,每个人都很高兴。
但是 - 当我创建了一个索引,我遇到了问题。我创建了一个空迁移任务为
PM> add-migration AddIdxToState
Unable to generate an explicit migration because the following explicit migrations are pending: [201310301258520_AddIdxToOutage]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
请原谅我的法语 - 但WT *?
似乎没有办法解决这个问题。我可以恢复到第一个idx添加之前的迁移步骤,再次添加idx'es,同样的事情再次发生。
你能告诉我我在这里失踪了什么吗?我究竟做错了什么?
编辑:
我最初以为我的麻烦正在执行针对数据库/生的LocalDB SQL,但似乎一切我现在做的第一附加迁移后停止。
我只是增加了一个新的表到数据库,这是从PM控制台STD-出结果:
PM> add-migration AddMyLoggerTable
Scaffolding migration 'AddMyLoggerTable'.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration 201310301419063_AddMyLoggerTable' again.
PM> update-database -startupproject DongEnergy.D3A.Data -verbose
Using StartUp project 'D3A.Data'.
Using NuGet project 'D3A.Data'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'D3A.Data.StorageContext' (DataSource: (localdb)\v11.0, Provider: System.Data.SqlClient, Origin: Convention).
Applying code-based migrations: [201310301419063_AddMyLoggerTable].
Applying code-based migration: 201310301419063_AddMyLoggerTable.
CREATE TABLE [dbo].[MyLoggerTable] (
[id] [int] NOT NULL,
[functionId] [int],
[elapsedTime] [bigint],
[noOfRecords] [int],
[dateCreated] [datetime] DEFAULT getDate()
)
[Inserting migration history record]
Running Seed method.
PM> add-migration AddMyLoggerTableFunction
Unable to generate an explicit migration because the following explicit migrations are pending: [201310301419063_AddMyLoggerTable]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
通知我如何添加一个新的空迁移任务,使用CREATETABLE法和有在数据库中成功更新。但是当我添加一个新的迁移步骤时,它会抱怨说刚刚“提交”到数据库的任务仍然是“未决” - 即使迁移历史记录和数据库对象都已更新。
尝试:还原,删除您的迁移并重新创建它。我几次遇到了“空”迁移的问题,但这个简单的技巧总是做到了。 –
@allo_man,好吧,我试过了。我恢复了迁移步骤/创建索引之前。这工作得很好。然后我添加了第一步创建索引。这工作得很好,更新数据库像预期的那样工作。当我添加迁移来创建第二个索引时,失败。 –
您的第一次迁移是否在__MigrationHistory表中创建了条目? – Adrian