![]() Or - Add-Migration MYMIGRATION -ConfigurationTypeName ConfigurationB -ProjectName Run command Add-Migration MYMIGRATION -ConfigurationTypeName ConfigurationA -ProjectName Steps to create migration scripts in Package Manager Console: Update-Database -ConfigurationTypeName ConfigurationA -ProjectName.NameOfMainProject -ConnectionStringName ContextA add-migration InitialSurveySchema -IgnoreChanges -ConfigurationTypeNameĬonfigurationA -ProjectName ProjectContextIsInIfNotMainOne -StartupProjectName.ProjectContextIsInIfNotMainOne -StartupProjectName NameOfMainProject Update-Database -ConfigurationTypeName ConfigurationB -ProjectName.add-migration InitialBSchema -IgnoreChanges -ConfigurationTypeNameĬonfigurationB -ProjectName ProjectContextIsInIfNotMainOne.Again, make sure the constructor is also renamed appropriately.Įdit ConfigurationB.cs: Change the namespace to StartupProjectName NameOfMainProject -ConnectionStringName ContextB NamespaceOfContext.ContextB -ProjectName ProjectContextIsInIfNotMainOne Enable-Migrations -EnableAutomaticMigrations -ContextTypeName.Make sure it does.Įdit ConfigurationA.cs: Change the namespace to This should automatically rename the constructor if using Visual Studio. StartupProjectName NameOfMainProject -ConnectionStringName ContextA NamespaceOfContext.ContextA -ProjectName ProjectContextIsInIfNotMainOne In Package Manager Console: Enable-Migrations -EnableAutomaticMigrations -ContextTypeName In SSMS, delete the _MigrationHistory system table.If Migrations are messed up and you want to create a new "baseline": Here are the specific steps that work well for me. If you do not, EF will attempt to apply migrations to the wrong context. In addition to what suggested, it is critical to give each renamed Configuration.cs its own namespace. To overwrite the existing migrations configuration, use the -Force parameter. If I run Enable-Migrations -ContextTypeName 1DbContext I'm not allowed to run Enable-Migrations -ContextTypeName 2DbContext because a migration already exists: Migrations have already been enabled in project 'DatabaseService'. To enable migrations for 2DbContext, use Enable-Migrations -ContextTypeName 2DbContext. ![]() To enable migrations for 1DbContext, use Enable-Migrations -ContextTypeName 1DbContext. More than one context type was found in the assembly 'DatabaseService'. How do I enable Entity Framework 5 (version 5.0.0) migrations for multiple DB contexts in the same project, where each context corresponds to its own database? When I run Enable-Migrations in the PM console (Visual Studio 2012), there's an error because of there being multiple contexts: PM> Enable-Migrations ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |