databaseentity-frameworkasp.net-corebackupentity-framework-migrations

Modify and delete tables and apply to DBContext


I had an old bank and store that stored user information and product information in the database.

Now I updated the store and changed many tables

On the other hand, I need to extract the previous information I got and use them.

Now I restored the previous bank.

But when I want to make a new migration, it does not allow me and says that this table already exists in the bank.

enter image description here

What should I do ?????

After several searches for this code

        public  MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {
            Database.EnsureDeleted();
            Database.EnsureCreated();
        }
    

1 _I have a backup from the previous database

2_It creates the tables but does not replace the information

3_I tried several other ways


Solution

  • Do these steps.

    1_Remove Migration Folder

    2_Remove _MigrationHistory Table Database

    3_Add-Migration Clever

    4_Just Delete Content Method up

    protected override void Up(MigrationBuilder migrationBuilder)
      {
          
      }
    

    inside (Do not delete the method itself)

    Do not remove the Down method

    5_Update-Database