marrrschine
marrrschine

Reputation: 632

EF Migration has no effect

I've started developing a backend without enabling dotnet ef migrations. I managed to start using migrations after a while with the help of .NET Core database model changes in production.

Now one of my models changed again and I wanted to apply another migration, this time not by script but directly inside the applications startup.cs with _myContext.Database.MigrateAsync(); where I basically renamed one field from myField to myFieldId. After starting up the application I can see the regarding log entries

Applying migration '20170908221458_MyMigration'.  
Opening connection to database 'database' on server '(local)\INSTANCE'. 
Beginning transaction with isolation level 'Unspecified'. 
Executed DbCommand (119ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DECLARE @var0 sysname;
SELECT @var0 = [d].[name]
FROM [sys].[default_constraints] [d]
INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
WHERE ([d].[parent_object_id] = OBJECT_ID(N'myTable') AND [c].[name] = N'myField');
IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [myTable] DROP CONSTRAINT [' + @var0 + '];');
ALTER TABLE [myTable] DROP COLUMN [myField]; 
Executed DbCommand (23ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE [myTable] ADD [myFieldId] xml NOT NULL DEFAULT 0; 
Closing connection to database 'database' on server '(local)\INSTANCE'. 

which are looking good. But my model didn't change inside the database! Also, my EFMigrationsHistory is missing a new entry. So on next application startup EF is trying to apply the migration again. Any ideas whats wrong here?

Upvotes: 1

Views: 357

Answers (1)

marrrschine
marrrschine

Reputation: 632

damn. My mistake was that I didn't perform a dotnet ef database update for my context locally, but just the dotnet ef migrations add.

Upvotes: 1

Related Questions