Enable-Migrations Exception calling “SetData” with “2” argument(s)

后端 未结 8 1697
小鲜肉
小鲜肉 2020-11-29 09:45

I created a library based on .NET 4.6.2 version.
To the library, I\'ve added the EntityFramework version 6.1.3 package.
I created a model as follow



        
相关标签:
8条回答
  • 2020-11-29 10:20

    To be free from defining startup project explicitly , you can use the command:

    Enable-Migrations -EnableAutomaticMigrations -ProjectName Components -StartupProjectName Components
    

    The parameters are:

    -ProjectName

    Specifies the project that the scaffolded migrations configuration class will be added to (configuration.cs). If omitted, the default project selected in package manager console is used.

    -StartUpProjectName

    Specifies the configuration file to use for named connection strings. If omitted, the specified project's configuration file is used.

    To get more details for the command, run:

    get-help enable-migrations -Full        
    
    0 讨论(0)
  • 2020-11-29 10:28

    if anyone is using visual studio 2017 then you might have to check for the following packages

    Nuget Packages

    Microsoft.EntityFrameworkCore
    
    Microsoft.EntityFrameworkCore.Tools
    
    Microsoft.EntityFrameworkCore.SqlServer
    

    after that run the migrations command below on console

    EntityFrameworkCore\Enable-Migrations
    
    EntityFrameworkCore\Add-Migration Book
    
    0 讨论(0)
  • 2020-11-29 10:38

    2018 update - if the accepted answer doesn't help, see this github issue on the EF6 repository. Apparently code migration commands don't work with the new project format. In order for the migrations commands to work, you need to create a Class Library (.NET Framework) project (old standard), move all the files there, add all the needed dependencies and run the command.

    EDIT: I just ran into this problem by creating a Class Library (.NET Standard) project on VisualStudio 2017 15.6.6 using EntityFramework 6.2.0. Creating an "old standard" project as explained above fixes it.

    0 讨论(0)
  • 2020-11-29 10:39

    I also had 2 versions of EF installed and using "EntityFrameworkCore\Add-Migration [migrationname]" command to specify which version to use solved the issue.

    0 讨论(0)
  • 2020-11-29 10:41

    This can happen if you have both Microsoft.EntityFrameworkCore.SqlServer installed alongside an older version of EntityFramework say 6.x

    In Visual Studio, go to Project/Manage Nuget Packages...

    Take a look through the Installed list and if more than one version of EntityFramework is installed, uninstall all older versions, leaving only the latest version.

    0 讨论(0)
  • 2020-11-29 10:42

    Edit: Simple fix (as stated above) -StartupProjectName YourEF6ProjectNameHere

    When I had been using the wrong StartupProjectName I still got the error. That's when I was using the solution below:

    My kludgy work-around is to unload the project that does not require EF migrations:

    1. Unload the startup project (in my case an ASP.Net Core project). Right-click the project name and selecting Unload Project.
    2. Run the needed migration commands in the Package Manager Console
    3. Right-click the unloaded project and choose Reload Project
    4. Right-click the same project and choose Set as StartUp Project.

    Not fun.

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