Your startup project doesn't reference Microsoft.EntityFrameworkCore.Design

后端 未结 15 732
天涯浪人
天涯浪人 2021-02-01 12:51

I have 2 projects in my solution, I have a project with Entity Framework Core installed:

And in the other ASP.NET Web API project I have these packages:

相关标签:
15条回答
  • 2021-02-01 13:06

    Set the project with entities as the Startup project and run the scaffolding command. it worked for me. Don't forget to set the revert the startup project after.

    0 讨论(0)
  • 2021-02-01 13:09

    I got this error because Visual Studio defaulted to using entity framework core rather than old-school entityframework for .NET Framework: entity framework 6. This was my solution:

    EntityFramework\Update-Database
    

    Or reference the version explicitly:

    EntityFramework6\Update-Database
    

    Also worth checking the right project is selected in the Package Manager Console. That likes to sneak back to other projects half the time!

    0 讨论(0)
  • 2021-02-01 13:09

    There is absolutely NO reason to install Microsoft.EntityFrameworkCore.Design to your API project while having a separate Data project.

    Quick solution

    When using add-migration, just add a parameter to set the -StartUpProject to your Data proj (by default I presume your startup project is the API proj).


    Example add-migration command below:

    add-migration {migration_name} -StartUpProject {your_data_proj_name} -project {your_data_proj_name} -v
    

    Example update-database command below:

    add-migration {migration_name} -StartUpProject {your_data_proj_name} -project {your_data_proj_name} -v
    

    I hope this help you guys

    PS: more info about the add-migration params can be found here

    0 讨论(0)
  • 2021-02-01 13:10

    I found the solution here: http://obscureproblemsandgotchas.com/development/c/dotnet-core-ef-migration-not-working/

    In short, edit your csproj file, and add to your PropertyGroup section following entry:

    <GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
    
    0 讨论(0)
  • 2021-02-01 13:12

    Try to set your web project again as startup project and this warning should go. (Right click on web project > Set as startUp project)

    0 讨论(0)
  • 2021-02-01 13:12

    In order for the migration tool to work, I had to add the Microsoft.VisualStudio.Web.CodeGeneration.Design NuGet package as well.

    0 讨论(0)
提交回复
热议问题