Efcore: Migration works within Package Manager but not CLI

Created on 20 Mar 2018  路  4Comments  路  Source: dotnet/efcore

After doing everything as described in the migration guide I'm still getting the error:

Unable to create an object of type 'Context'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

Adding a migration or running Update-Database from Package Manager Console works just fine but running dotnet ef database update fails.

Sample code can be found here: https://github.com/thiagomajesk/ASP.NET-Core-Bootstrap-Template

closed-question

All 4 comments

@thiagomajesk - It could be arising from multiple projects scenario.
Can you tell us

  • What is your startup project in VS?
  • What is the project selected in Package Manager Console while running Update-Database?
  • From which project directory are you running dotnet ef database update command?
  • Are you passing in project/startup-project arg to dotnet ef? One of them may be needed since your DbContext is not in same project as your Startup.cs

@smitpatel

  • What is your startup project in VS?
    Project.Web
  • What is the project selected in Package Manager Console while running Update-Database
    Project.Web
  • From which project directory are you running dotnet ef database update command?
    Project.Infra
  • Are you passing in project/startup-project arg to dotnet ef? One of them may be needed since your DbContext is not in same project as your Startup.cs
    No since I'm running directly from the directory and supposed it should work

Can you run dotnet ef with --startup-project switch pointing to your Project.Web project file and see if that works?

@smitpatel It works if run dotnet ef --startup-project ../Project.Web database update from the Project.Infra folder. I've added a note to the docs because I don't think it is explicit enough about that. Thanks!

Was this page helpful?
0 / 5 - 0 ratings