简体   繁体   中英

Save data during Migration Entity Framework Core

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM