Using the Package Manager Console I can run a command similar to the following one
Update-Database -ProjectName: My.Project.Data
The command triggers migrations on MyDbContext
defined within the project My.Project.Data
located in the currently open solution. Good.
Now the project My.Project.Data
resides in the same solution with project My.Project.Mvc
. The problem is, My.Project.Mvc
uses two db contexts. One that we already covered and another one defined within project Core.Project.Data
- this one is built as a NuGet package which is then referenced by My.Project.Mvc
. The diagram below should make it clear:
MySolution
├┬ My.Project.Mvc
│├─ references: My.Project.Data (in the same solution)
│└─ references: Core.Project.Data (NuGet)
└─ My.Project.Data [MyDbContext]
CoreSolution
└─ Core.Project.Data [CoreDbContext]
The question is, how can I trigger the migrations for the CoreDbContext
from the Package Manager Console of MySolution
. If I try to run Update-Database -ProjectName: Core.Project.Data
I get the error:
Get-Project : Project 'Core.Project.Data' is not found.
Update: Using the migrate.exe instead is not an option.
From the document update-database does not support dll.
You can execute EF migration tool from commandline, or add it in VS menu for conveniences.
migrate.exe Core.Project.Data.dll /startupConfigurationFile=Core.Project.Data.dll.config
or change /startupConfigurationFile
to /connectionString=your-connection-string
When migrations are first enabled by Enable-Migration
, a Configuration.cs
file will be added to the project. If this file exists for Core.Project.Data
, tell Entity Framework to use this config:
Update-Database -ConfigurationTypeName Core.Project.Data.Migrations.Configuration -ProjectName Core.Project.Data