Unable to generate an explicit migration in entity framework

后端 未结 28 1225
情书的邮戳
情书的邮戳 2020-12-12 23:31

I am adding a new migration but this message shows:

Unable to generate an explicit migration because the following explicit migrations are pending:

相关标签:
28条回答
  • 2020-12-12 23:55

    I had a simpler problem. VS erroneously reported this error when I had a VPN connection to a client's site connected on my workstation. The problem was that the DBMS security was set to accept requests only from my real local IP. Simply turning off the VPN resolved the problem.

    0 讨论(0)
  • 2020-12-12 23:56

    You either need to run "update-database" from the package manager console to push your changes to the database OR you can delete the pending migration file ([201203170856167_left]) from your Migrations folder and then re-run "add-migration" to create a brand new migration based off of your edits.

    0 讨论(0)
  • 2020-12-12 23:56

    When running into this issue, please try adding parameters to your add-migration cmdlet. For example, specifying the start up project as well as the connection string name could help EF find your target database.

    add-migration Delta_Defect_0973 -ConfigurationTypeName your.namespace.ContextClassName -StartUpProject DeltaProject -ConnectionStringName DeltaSQL
    

    Where:

    Delta_Defect_0973 is the name of your migration

    your.namespace.ContextClassName is the name of your Configuration class in your migration folder, prefixed with the full name space.

    DeltaProject is the name of your main project with your web.config or app.config file.

    DeltaSQL is the name of your connection string defined in your web.config or app.config file.

    0 讨论(0)
  • 2020-12-12 23:56

    My local database did not have the __MigrationHistory populated, or existing. I manually created the table, and then migrated the data in that table from PROD to my local database. This caused VS to think the migrations had been applied (which they had been).

    0 讨论(0)
  • 2020-12-12 23:57

    Old post but might help someone. For me it happened because I renamed Assembly name and Default namespace of the project. So I had to update ContextKey in _MigrationHisotry table to the new value of Assembly name or Default namespace. Honestly I don't know which one should be used, because for me both are same!

    0 讨论(0)
  • 2020-12-12 23:58

    There is an ambiguity and so error. Best way is to exclude the current migration file and create new migration(add-migration) file and then copy the content of new migration to excluded file and include it again and run update-database command.

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