EF 6.2.0 shows error 'The model backing context has changed since the database was created' when I update a column on the DB

Viewed 31

I am trying to increase the column lenght, by using EF 6.2.0, VS 2019 and SQL Server Management Studio 18,12,1 by creating a new migration and updating manually the model, so that:

    I follow the next steps
    1.Alter Model by using the next attributes:
            [Required]
            [StringLength(300)]
            public string MyColumn { get; set; }
    
    2. Create new Migration
 

    public override void Up()
            {
                AlterColumn("myTable", "myColumn", c => c.String(maxLength: 300));
            }
    
            public override void Down()
            {
                AlterColumn("myTable", "myColumn", c => c.String(maxLength: 255));
            }
       
  
    3.Run the Migration in the Package Manager Console
 

     PM> Update-database -force          
     
    4.Checking the DB Changes abd the column maxLenght is updated properly    
    [1]

    5.Debug the application but got the next error: 

      "The model backing context has changed since the database was created"
      
    Any thoughts, will be appreciated!
1 Answers
I solve it by adding the SetInitializer method over the DataContext constructor:
 public ReportsDataContext()
            : base(Settings.GetConnectionString())
        {
            Configuration.LazyLoadingEnabled = false;
            Configuration.ProxyCreationEnabled = false;
            //*********Adding this line*********
            Database.SetInitializer<ReportsDataContext>(null);
            InitContext();
        }
Related