EF data migration

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.