asp.net-coreentity-framework-coreef-core-3.1

Drop table using SQL and to run migrations on EF Core


I created a table Documents using Entity Framework Core and the Add-Migration command. I also did some modifications related to foreign key in Table 1 using EF Core migrations and updated the database.

But after some time, I dropped the table Documents using a SQL drop table command instead of deleting it.

Now, how can I sync up my database with my migration state in code? Is there a command to run set of migration from migration mig1 to mig2 and update database?


Solution

  • The problem you have is that your snapshot is out of sync with your actual database.

    To fix it:

    1. In your migration snapshot comment out the code that relates to the specific table you deleted.

    2. Do a new migration (add-migration) to 'introduce' your previously deleted table to EF

    3. update-database to apply your migration