Question
The model that supports the "appcontext" context has been changed after the database is created. Please consider using code first to migrate and update the database
Causes and Solutions
During the development in EF codefirst mode, classes are inevitably modified. After the modification, an exception occurs when running again, prompting that the context model has changed after the database is created.
If it is the initial development of the project, it is easy to delete the database and re-establish it. However, if the project is already running, I don't think you would like to do that in the early stage, it will be lost. At this time, you need to use the data migration feature of EF. The following describes how to use data migration.
Open vs, tools> Program Package Manager> Package Manager Console.
EnterEnable-migrations(Case Insensitive ).
After entering this command, the migrations folder will be created in the project, which contains two files
1: configuration. CS allows you to configure the appcontext context migration behavior. For example, you can add some data initialization operations.
2: 201403310555286_initialcreate.cs. The file name is composed of Timestamp + underline + initial. cs. This class contains the code for creating the database architecture.
Generate and run migration
22323
EF data migration