How to change the output folder for migrations with asp.net Core?

自闭症网瘾萝莉.ら 提交于 2019-11-27 21:06:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!