116

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?

7 Answers 7

202

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>

Sign up to request clarification or add additional context in comments.

7 Comments

I don't approve of your second comment. :) Both the Package Manager Console and .NET Command Line Tools are equally legit.
Sorry Brice :) I absolutely agree that both are legit, but PMConsole have long history (from VS 2013 or even earlier?), while CLI is more new/young and cross-platform, so I used word "modern" (beer)
there is no target parameter
@Dmitry do you know how to do this via C# code?
There is no -target parameter . Please remove it.
|
91

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

2 Comments

Can confirm. core 2.0 uses -migration. -target is no longer reconized
This applies all the missing migrations up to the provided one (test32), which is what you normally want since migrations might one upon the other and must be run in order.
32

For EF Core 3.1 via Package Manager Console:

dotnet ef database update YourMigrationName

Comments

5

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

Comments

1

For mac OS i did like this working for me

dotnet ef database update -c ApplicationDbContext

Comments

1

in EF Core 8 and 9 simply:

update-database MigrationName

1 Comment

Reading all the answers here, it seems like over the different versions of EF Core, the syntax has changed. Can you edit this answer to specify which version this applies to?
1

okey, just to have commands for every version of EF in one place, for EF6 it is:

update-database -TargetMigration <full migration name including id>

(origin: https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#migrate-to-a-specific-version-including-downgrade )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.