It is not possible to update the database according to the current model because there are pending changes and automatic migration is disabled

I, for the life of me, cannot get rid of this error message. I tried almost everything I can.

MyDBContext.cs

        public MyDBContext() : base("ConnStr_Dev")
    {

    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDBContext, DbMigrationsConfiguration<MyDBContext>>());
        //Database.SetInitializer<MyDBContext>(null);
        base.OnModelCreating(modelBuilder);
    }

GenericRepository.cs

        public void Insert(T obj)
    {
        table.Add(obj);      //this is where it throws the error, inserting first time.
    }

Tried it all in different combinations.

Enable-Migrations -EnableAutomaticMigrations -Force

Add-migration Initial -IgnoreChanges

Update database

I tried to delete the Migrations table, deleting the entire database, that's all.

Any migration experts?

Edit: DAL contains a GenericRepository and a context class.

+4
source share
5 answers
  • Migrations
  • dbo.__MigrationHistory
  • Package Manager Console Enable-Migrations
  • Add-Migration Initial
  • Update-Database
+3

. , , .

, , , Add-Migration , , DBContext, . , (DbContext) MyDBContext. , .

, Add-Migration Update :

:

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

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

, .

+1

DatabaseInitializerForType... appSetting.

<appSettings>
<add key="DatabaseInitializerForType EasyEntity.EasyContext, EasyEntity"  value="EasyEntity.EasyInitializer, EasyEntity" />
0

, CONNECTIONSTRING, , . , !

0

. , , , , .

: IMigrationMetadata.Target . . ( .)

, , , , .

, , . , , , , . , ( EF), , , , .

0

Source: https://habr.com/ru/post/1673770/


All Articles