How to unapply a migration in ASP.NET Core with EF Core

前端 未结 16 2152
余生分开走
余生分开走 2020-12-07 08:10

When I run PM> Remove-Migration -context BloggingContext in VS2015 with an ASP.NET Core project using EF Core I get the following error:

Syst         


        
相关标签:
16条回答
  • 2020-12-07 08:47

    You should delete migration '20160703192724_MyFirstMigration' record from '_EFMigrationsHistory' table.

    otherwise this command will remove migration and delete migrations folder:

       > remove-migration -force
    
    0 讨论(0)
  • 2020-12-07 08:47

    In order to unapply a migration in EF Core 1.0 use the command:

    dotnet ef database update {migration_name}

    Use the migration name of the migration until which you would like to preserve your changes. The list of names of the migration can be found using:

    dotnet ef migrations list

    0 讨论(0)
  • 2020-12-07 08:51

    In general if you are using the Package Manager Console the right way to remove a specific Migration is by referencing the name of the migration

    Update-Database -Migration {Name of Migration} -Context {context}
    

    Another way to remove the last migration you have applied according to the docs is by using the command:

    dotnet ef migrations remove
    

    This command should be executed from the developer command prompt (how to open command prompt) inside your solution directory.

    For example if your application is inside name "Application" and is in the folder c:\Projects. Then your path should be:

    C:\Projects\Application
    
    0 讨论(0)
  • 2020-12-07 08:53

    To completely remove all migrations and start all over again, do the following:

    dotnet ef database update 0
    dotnet ef migrations remove
    
    0 讨论(0)
  • 2020-12-07 08:53

    in Package Manager Console, just Type Remove-Migration And Press Enter. It automatically removes the migration.

    Tools -> Nuget Package Manager -> Package Manager Console

    0 讨论(0)
  • 2020-12-07 08:55

    at first run the following command :

    PM>update-database -migration:0
    

    and then run this one :

    PM>remove_migration
    

    Finish

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