Unable to generate an explicit migration in entity framework

后端 未结 28 1226
情书的邮戳
情书的邮戳 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:48

    I had this problem too for a database that I knew was up to date when running Add-Migration. Solved by simply running the Add-Migration command a second time. Suspect a connectivity issue, as suggested by Robin Dorbell above.

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

    This error can also mean that the migrations are not recognized anymore. This happened to me after having changed the value of the ContextKey in Migrations.Configuration. The solution was simply to update the ContextKey in the database table "__MigrationHistory" (or revert the value in the Configuration class I guess). The ContextKey and the Namespace in your application should match.

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

    i solved same problem like this:

    • delete old migration file
    • update-database -force
    • Add-Migration AddedEntity
    • update-database
    0 讨论(0)
  • 2020-12-12 23:51

    In my case, I forgot to add my IP address in firewall rules in Azure, basically as I was unable to connect to the database I was getting this error. So specifically for my case, I added my IP address in database firewall rules in Azure and it all worked well. Apart from this, it could be the issue of proxy/internet connection/DB username password/DB connection string etc. OR obviously, you might have pending migrations for which you need to run Update-Database command.

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

    I suffered exactly the same problem just after reverting from a migration to another.

    In my case I "targetedmigration" from "migration06" to "migration04".

    I needed to delete the "migration0"6 and then I was able to force creating the "migration05". This basically means that you need to just keep the next migration after the targeted one.

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

    Just my two cents:

    My scenario:

    1. I restored my local database to a working state.
    2. Already had migrations already applied to it.
    3. Whenever I tried adding a new migration i got the error about pending migrations as mentioned my the OP.

    Solution:

    To get around this i just provided more explicit parameters:

    Add-Migration -ConnectionString "Server=localhost\SQLEXPRESS;Database=YourDataBase;Trusted_Connection=True;" -ConnectionProviderName "System.Data.SqlClient" -verbose
    

    I am lead to believe that you can set a setting in your app.config folder to allow you to default this behaviour so you don't have to provide explicit parameters everytime. However I am not sure on how to do this.

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