Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate full SQL script from EF 6 Code First Migrations and Multiple Configurations

I'm trying to generate a full SQL script to deploy my application for the first time. I know that this command from the package manager console is supposed to create a full SQL script (see this SO question)

Update-Database -Script -SourceMigration:0 

I've also read that $InitialDatabase is supposed to work instead of '0' for the source migration.

However, I have two configurations in my migrations folder. I'm using the following syntax for it:

Update-Database -Script -SourceMigration:0 -ConfigurationTypeName MyConfig

I'm getting back an empty script for all my configurations.

As a note, I have automatic migrations enabled and haven't added any explicit migration to it.

like image 312
Leonardo Herrera Avatar asked Nov 12 '22 19:11

Leonardo Herrera


1 Answers

Having two migrations configurations in the same namespace is an unsupported scenario. We closed a bug similar to this as "by design" recently. The workaround is to have your migrations configurations in separate namespaces.

The most reliable solution to this issue would just be to put your configurations in different folders and use the MigrationsDirectory variable as shown below, then any explicit migrations generated for the configuration should be placed in the same folder

    internal sealed class Configuration : DbMigrationsConfiguration<TestMultipleMigrationsScript.BlogContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
        MigrationsDirectory = @"directory";
    }

}
like image 98
lukew Avatar answered Nov 15 '22 00:11

lukew