stian64
stian64

Reputation: 1683

Entity framework Core Update-database specific migration

I am trying to figure out how to run a specific migration from the package manager in nuget.

I have tried to run:

 update-database -TargetMigration test32

But I do get this message:

A parameter cannot be found that matches parameter name 'TargetMigration'.

How can this be resolved?

Upvotes: 113

Views: 183851

Answers (6)

Elnoor
Elnoor

Reputation: 3762

in EF Core 8 and 9 simply:

update-database MigrationName

Upvotes: 0

Dmitry
Dmitry

Reputation: 16825

According to EF Core Docs, correct parameter name is -Target (for EF Core 1.1) or -Migration (for EF Core 2.0)

so in your case, for EF 1.1:

update-database -target test32

or, for EF 2.0 and later:

update-database -migration test32

"Modern" way is to use "regular" command prompt and .NET Core CLI, and command like dotnet ef database update <target>

Upvotes: 194

sweetnandha cse
sweetnandha cse

Reputation: 1031

For mac OS i did like this working for me

dotnet ef database update -c ApplicationDbContext

Upvotes: 0

SimpleUser
SimpleUser

Reputation: 1351

Just wanted to add to what Plastiquewind mentioned. In the current version, there is no -target parameter. You have to use -migration. Also, you can specify the context (if you have more than one) with the -context parameter.

Update-database -context MyContext -migration MyMigration

Upvotes: 5

Stewart Cunningham
Stewart Cunningham

Reputation: 760

For EF Core 3.1 via Package Manager Console:

dotnet ef database update YourMigrationName

Upvotes: 32

Plastiquewind
Plastiquewind

Reputation: 918

The best answer given by Dmitry is a bit incorrect. There's no parameter -Target. The only parameter that can be applied is -Migration. Therefore, the right answer is:

Update-Database -Migration test32

Upvotes: 90

Related Questions