How do I force drop and re-create a a selected table in code-first migration?
There is another option for this:
- Manually drop tables you want to recreate
- Remove records from "__EFMigrationsHistory" table that are linked to your deleted tables
- Run "update-database"
It should run all migrations that are not in history once again. Be careful with this if you have migrations that touches more than one table. You may need to omit some migrations and than add changes manually.
Deleting DbSets from Context should also work and is probably better, but for me in Entity-Framework-Core it hasn't worked at all.
I can see two possible ways:
- Drop the table from database
- Generate a new migration (using
Add-Migration
). A new migration that creates the missing table will be generated - Execute Migration (using
Update-Database
)
OR
- Remove the entity from the context (remember to remove all relationships with others entities)
- Generate a Migration using
Add-Migration
(it will generate a drop table method) - Execute Migration using
Update-Database
- Add the entity to the context
- Generate a new Migration using
Add-Migration
(it will generate a create table method) - Execute Migration using
Update-Database
Hope it helps!