Visual Studio Code Entity Framework Core Add-Migration not recognized

前端 未结 5 1027
青春惊慌失措
青春惊慌失措 2021-02-02 09:53

I\'ve used yoman to generate an ASP.Net Core Web API application via the Visual Studio Code Editor. For reference, I followed this tutorial here

The API works fine. Ho

相关标签:
5条回答
  • 2021-02-02 10:01

    The correct format to add a new migration is dotnet ef migrations add yourMigrationName

    and to update database is dotnet ef database update

    0 讨论(0)
  • 2021-02-02 10:05

    Step 1 First we need to add reference in *.csproj file in the following way

    Step 2 in Bash/Command propt

    dotnet restore

    Step 3

    dotnet ef migrations add MyDbInitialMigration

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

    You need to add:

    dotnet tool install --global dotnet-ef
    
    0 讨论(0)
  • 2021-02-02 10:17

    In this case, the project must be checked first. Migration cannot be initiated if there is any error in the project.

    0 讨论(0)
  • 2021-02-02 10:23

    Im working on Mac, so Ruby is installed by default. My EF commands required lots of extra parameters --project, --startup-project etc. This was a pain to type every time, so I used rake to make this easier.

    In my project root, I added a file called rakefile with these contents:

    desc "Add Migraion"
    task :'add-migration' do
        ARGV.each { |a| task a.to_sym do ; end }  
        puts ARGV[1]
        sh "dotnet ef migrations add " + ARGV[1] + " --project MyProject.Data/MyProject.Data.csproj --startup-project MyProject.Web/MyProject.Web.csproj "
    end
    
    desc "Remove Migraion"
    task :'remove-migration' do
        ARGV.each { |a| task a.to_sym do ; end }  
        puts ARGV[1]
        sh "dotnet ef migrations remove --project MyProject.Data/MyProject.Data.csproj --startup-project MyProject.Web/MyProject.Web.csproj"
    end
    
    desc "Update Database"
    task :'update-database' do
        ARGV.each { |a| task a.to_sym do ; end }  
        puts ARGV[1]
        sh "dotnet ef database update --project MyProject.Data/MyProject.Data.csproj --startup-project MyProject.Web/MyProject.Web.csproj"
    end
    

    Then at the command line, I run these commands:

    rake add-migration <migrationName>
    rake remove-migration
    rake update-database
    
    0 讨论(0)
提交回复
热议问题