Save data during Migration Entity Framework Core

asp.net-core c# ef-migrations entity-framework-core

Question

I want to save data during Migration. But after migration Database is empty. I Use next params for migration in my DBContext

Database.EnsureDeleted();
Database.EnsureCreated();

But after I have Database without data

1
0
4/2/2020 9:54:42 AM

Accepted Answer

As stated in the Create and Drop APIs documentation you should not use EnsureDeleted / EnsureCreated when using Migrations, as EnsureDeleted will drop your database (and with it your data), and EnsureCreated will recreate it from scratch (schema only). See the Migrations documentation for further information about creating migrations without loosing data.

1
4/2/2020 8:17:08 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow