How to force delete and re-create the selected table during the first code migration?

I want to delete a table with thousands of columns and let the migration recreate it. I can release

    DropTable("MyTableWithManyColumns");

But the problem is that I would make a manual creation table like this

    CreateTable(
            "dbo.MyTable",
            c => new
                {
                    RowId = c.Int(nullable: false, identity: true),
                    // many columns follow...
                })
            .PrimaryKey(t => t.RowId);

An easier way to do this is to use SSMS and right-click Drop Create Table in a new window and run from there.

But is there an easy way to use code migration?

+9
source share
4 answers

I see two possible ways:

  • Drop table from database
  • ( Add-Migration). , .
  • ( Update-Database)

  • ( )
  • Add-Migration ( )
  • Update-Database
  • Add-Migration ( create table)
  • Update-Database

, !

+10

:

  1. ,
  2. "__EFMigrationsHistory",
  3. "update-database"

, . , , . , , .

DbSets Context , , , Entity-Framework-Core .

+4

, . - .

, :

SQL Management Studio ( , , , ). (FK), .., MyTable. SQL- MyTable. , , (, ), , FK.

Just to check the database, I tried to make changes to the database.

ADD-MIGRATION XYZ
UPDATE-DATABASE -VERBOSE

Everything worked.

0
source
  1. Delete the Migration folder with additional content.
  2. How to manually delete tables
  3. Run the update-database command from the package manager console

Everything will work correctly. Successful coding.

0
source

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


All Articles