I want to drop a table with a thousand columns and let migration re-create it. I can issue a
DropTable("MyTableWithManyColumns");
But the problem is I would do a manual create table like this
CreateTable(
"dbo.MyTable",
c => new
{
RowId = c.Int(nullable: false, identity: true),
// many columns follow...
})
.PrimaryKey(t => t.RowId);
The easier way to do this is use SSMS and right click Drop Create Table to new window and execute from there.
But is there is there an easy way using code migration?
Delete table from database using entity framework core code first approach is so simple you have to remove or comment that table from context file, add migration and then update the database. Now you can see that your table is removed from your database.
I can see two possible ways:
Add-Migration
). A new migration that creates the missing table will be generatedUpdate-Database
)OR
Add-Migration
(it will generate a drop table method)Update-Database
Add-Migration
(it will generate a create table method)Update-Database
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With