We use the first code conversions with EF5 on (localdb) \ v11.0 (Vstudio 2012), and everything went well.
However - today I needed to create a couple of indexes on several tables and run into problems.
First I did it in PM:
PM> add-migration AddIdxToOutage Scaffolding migration 'AddIdxToOutage'.
I modified the code in the forest migration:
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]"); }
I updated the database and the result was as follows:
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.
X was created on the table, and everyone was happy.
However - when I created the following index, I ran into problems. I created an empty migration task as
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.
Excuse my French - but WT *?
It seems that this is not so. I can go back to the migration step before adding the first idx, add idx'es again and repeat the same thing.
Can you tell me what I am missing here? What am I doing wrong?
Edit:
Initially, I thought that my problem was that I was executing raw SQL against the / localdb database, but it seems like everything I do now stops after the first add-migration.
I just added a new table to the database, and this is the std-out result from the PM Console:
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.
Notice how I add a new, empty migration task, use the CreateTable method and successfully updated it in the database. But when I add a new transition step, he complains that a task that was simply βfixedβ in the database is still βwaitingβ - although both migrationhistory objects and databases are updated.