How to generate code first migration script from a specific migration?


I have a production and a development database. Now I want to generate a sql script based on a specific migration. When I enter the line to generate the script I get this error:

'201608121243147_AutomaticMigration' is not a valid migration. Explicit migrations must be used for both source and target when scripting the upgrade between them.

The command I use is as follows:

Update-Database -Script -SourceMigration:201608121243147_AutomaticMigration -TargetMigration:201608281101542_AutomaticMigration

When I execute the command get-migrations I can see those two migrations are in the list. The target migration is also my latest migration, but when I omit this parameter I get the same exception.

What am i doing wrong? What do I have to do to fix this?


Try removing the semicolon after SourceMigration and after TargetMigration:

Update-Database -Script -SourceMigration 201608121243147_AutomaticMigration -TargetMigration 201608281101542_AutomaticMigration


This works for me.

Update-DataBase -Script -SourceMigration:"Version1" -TargetMIgration:"Version2"

Regards Abdul


  • jQuery DOM element creation vs innerHTML
  • How do I Select Highest Number From Series of _# File Names in Bash Script
  • Bash: parsing XML block into an array
  • DropColumn conditionally in a migration
  • Is it possible to set breakpoints automatically (e.g. by regular expression) in VS2008?
  • Does Django natively support migrations
  • How to add a stop execution command in a batch file
  • Get All Connected Users (Laravel 5)
  • How do I disable the access denied message when trying to do cross scripting into an iframe?
  • Is it possible to change mysql DB encoding charset from within a laravel migration?
  • PHP or Python for Image Processing?
  • Declaring a dictionary in VBA
  • IE stop message “the web page you are viewing is trying to close the tab..\"
  • Creating a table in “MSWord” document out of a text in a .txt file
  • DotNet version of Windows Scripting Host
  • .Settings file in Win Form App, Best Practice
  • Unable to connect to remote MySql server in Asp.Net
  • How do you copy a MS SQL 2000 database programmatically using C#?
  • Mercurial vs Subversion. Whose performance is better?
  • Visual Studio 2012, Publish (Web Deploy) - Code First Migrations not changing web.config
  • redirect_to root_url and return unless @user.activated
  • MySQL performance when updating row with FK
  • How to explicitly/implicitly implemented interface members in C++/CLI?
  • Symfony 2. CSRF token is invalid
  • How to make jdk.nashorn.api.scripting.JSObject visible in plugin [duplicate]
  • uniform generation of points on 3D box
  • Unable to decode certificate at client new X509Certificate2()
  • How do I fake an specific browser client when using Java's Net library?
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Volusion's generic SQL folder, functionality
  • Release, debug version and Authorization Google?
  • Google cloud sdk not working when python points python3
  • Apache 2.4 - remove | delete | uninstall
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Is there a mandatory requirement to switch app.yaml?
  • python regex in pyparsing
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass