0

I have two databases, DEV and TEST.

DEV is maintained by me and I have been developing away for the last few weeks using code first migrations.

TEST is managed by DBAs who want SQL scripts to be provided in order to update the database to the most recent version.

This is my first time using code first in this scenario, I assume that I would need to use the command

Update-Database -Script 

However its not quite as simple as that.

What I am looking for is a way to specify which migration was last applied to the database.

So for example I have migrations numbered v1.0, 1.1, 1.2, 1.3, 1.4 etc

I know that TEST is currently running v1.2 and DEV is on 1.6, I want to update TEST to 1.5 (Note that this is not the most recent version) what is the command to build that script?

I tried

update-database -Script -TargetMigration "v1.5" 

however this compares migration 1.5 to my DEV database which gives me a script which rolls back from v1.6 that dev is on back to 1.5 rather than a script to update to 1.6

I know I can change the connection string in the project to point at the TEST database and then run the command, however that seems like a workaround - there must be a way that I can specify what migration to start at and what migration to script up to?

Ideally I want to do this without rolling my dev database back to the same version as TEST.

1 Answer 1

1

If you run the following in your package manager console you get the detailed help for the Update-Database command:

get-help Update-Database -detailed 

From there you can see the parameters, and I think this is what you need.

-SourceMigration <String> Only valid with -Script. Specifies the name of a particular migration to use as the update's starting point. If omitted, the last applied migration in the database will be used. -TargetMigration <String> Specifies the name of a particular migration to update the database to. If omitted, the current model will be used. 
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I needed. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.