EF core add migrations in ASP.net core multilayered architecture

asp.net-core c# command-line entity-framework-core

Question

I have recently started ASP.net core project with multilayered architecture, where CatalogDbContext and StartUp class in different layers:

enter image description here

I want to add migrations to DroneStore.Data layer. I change in command prompt current directory to ../DroneStore.Data/ and add command:

dotnet ef migrations add Initial

And got an error:

Unable to create an object of type 'CatalogDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

When I change current directory to ../DroneStore.Web/ and add this command i got error:

Your target project 'DroneStore.Web' doesn't match your migrations assembly 'DroneStore.Data'. Either change your target project or change your migrations assembly

Any suggections?

1
2
2/14/2019 8:17:47 AM

Accepted Answer

1) Change your currend directory in command prompt to:

cd ../DroneStore.Data/

2) Add to command -s option with path to StartUp project folder:

dotnet ef migrations add Initial -s ../DroneStore.Web/

2
2/14/2019 10:15:32 AM


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