问题
Does anyone know how to change the output directory of the following command:
dotnet ef migrations add Initial --context EsportshubApi.Models.ApplicationDbContext
??
i tried to add the option:
--content-root-path 'Migrations/Identity'
but that doesn't do anything. There is a --data-dir option aswell and something else with directory, but none of them is the output for migrations.
My problem is that i have 2 DbContexts so i want their migrations separated.
回答1:
dotnet ef migrations add Initial --context EsportshubApi.Models.ApplicationDbContext -o YourFolderPath
Source
dotnet ef migrations add
Adds a new migration.
Arguments:
< NAME > The name of the migration.
Options:
-o --output-dir < PATH > The directory (and sub-namespace) to use. Paths are relative to the project directory. Defaults to "Migrations".
回答2:
For Package Manager Console
run this command:
PM> Add-Migration 001 -OutputDir "Data/Migrations"
My structure is:
.AspCoreProject
-Data
-Migrations
20190721162938_001.cs
MainDbContextModelSnapshot.cs
回答3:
You just need to use -o Or --output option with your command,
To do so, you need to explore to your root project folder, eg: C:\project\SampleAPi\ and use this command
dotnet ef migrations add DbInitial --context SampleAPi.Infrastructure.DbContext -o Infrastructure/Migrations
and then
dotnet ef database update
来源:https://stackoverflow.com/questions/40696305/how-to-change-the-output-folder-for-migrations-with-asp-net-core