Unable to update database to match the current model because there are pending changes and automatic migration is disabled

后端 未结 5 832
渐次进展
渐次进展 2021-01-13 07:40

I, for the life of me, can\'t get rid of this error message. I have tried almost everything that I can.

MyDBContext.cs

        public MyDBContext() :         


        
5条回答
  •  情歌与酒
    2021-01-13 07:52

    You simply made changes to one or more of your entity classes. Whether you added a new property, changed the data type of that particular property or you simply added a new entity class, in all of those cases you indeed need to add a new migration.

    Seeing that you've already tried that, make sure that when you execute the Add-Migration command in Package Manager Console that you've selected the project that contains your DBContext class, the Configuration class and Migrations folder. Furthermore, you are passing a specific connection string to the base class (DbContext) of the MyDBContext class. Make sure you are also upgrading and updating the correct database.

    Know that you can perform an Add-Migration command and an Update command to a specific database:

    Example snippets:

    Add-Migration AddProperty1 -ConnectionString "Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabaseCatablog;Connect Timeout=30;User ID=MyUser;Password=mypassword12345" -ConnectionProviderName "System.Data.SqlClient" -Verbose
    

    and

    Update-Database -ConnectionString "Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabaseCatablog;Connect Timeout=30;User ID=MyUser;Password=mypassword12345" -ConnectionProviderName "System.Data.SqlClient" -Verbose
    

    Hope this helps.

提交回复
热议问题