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

asp.net asp.net-core command-line-interface database entity-framework

Question

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 as well 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 to be separated.

1
48
2/27/2020 9:00:40 AM

Accepted Answer

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".

66
1/15/2020 7:52:20 AM

Popular Answer

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

Update:

For removing last migration use:

PM> Remove-Migration

Note: If the migration is already applied to the database, then you will get this error:

The migration '20190721162938_001' has already been applied to the database. Revert it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration.

Then run:

PM> Remove-Migration -Force


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow