5

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.

Community
  • 1
  • 1
Leonardo Herrera
  • 8,388
  • 5
  • 36
  • 66

1 Answers1

2

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";
    }

}
lukew
  • 880
  • 7
  • 8
  • 1
    They are in different namespaces (and the actual context classes in different assemblies if that matters.) I can use "update-database" willy-nilly inside the package manager and it works flawlessly. It just doesn't generate SQL code (my workaround is just to export the DDL using SSMS.) – Leonardo Herrera Oct 30 '13 at 00:06
  • The scenario where two migrations configurations have different namespaces should be supported even if they are in the same directory. If you can repro this situation could you log a bug at entityframework.Codeplex.com ? I edited my solution above with some example code for specifying the MigrationsDirectory which is the recommended way to have multiple migrations contexts per solution – lukew Oct 30 '13 at 17:25
  • As I said, updating the database directly from the framework manager works perfectly. It's just the SQL script that doesn't get generated. – Leonardo Herrera Oct 30 '13 at 18:22