Createdata-baseifnotexists, such as the previous API has been deprecated, is now using the Microsoft packaged, simplified, efficient API,migrations
Because the old API has to pay a high price, and the limitations
Open VS2017, select Tools->nutget Package Manager--Packages Manager console
1. Enter add-migration myfirstmigration instruction
The Migrations folders and files are automatically generated based on the current DbContext, which are used to create or extend a database that is specifically owned by the Migrations API.
Then in ASP. Startup.cs file, public void Configure (Iapplicationbuilder app, Ihostingenvironment env, iloggerfactory Loggerfactory)
Configure this function, plus
2.update-database Upgrading the Database
[CSharp]View PlainCopyprint?
- using (var servicescope = app. Applicationservices.getrequiredservice<iservicescopefactory> (). Createscope ())
- {
- Servicescope.serviceprovider.getservice<unicornstorecontext> (). Database.migrate ();
- Servicescope.serviceprovider.getservice<applicationdbcontext> (). Database.migrate ();
- Servicescope.serviceprovider.getservice<unicornstorecontext> (). Ensureseeddata ();
- }
Replace your own function with the code above to
You can then generate a proprietary database of Mingrations APIs based on the files in the generated Mingrations folder, automatically scaling, and upgrading the database
Reprint: http://blog.csdn.net/loongsking/article/details/63682952
ASP. NET Core EF core (Entity Framework 7) database Update maintenance