EF modifies model Automatic Update database

Source: Internet
Author: User

Recently with MVC+EF study encountered modified model and the database did not update the error, on the Internet to find about the data migration automatically update the database, tossing the most of the day finally get out

Step one: In the Package Manager console: Enable-migrations-projectname the name of the project where EF is located

Second step: After running, the Migrations folder will be generated in the field, Migrations->configuration.cs class to change the automaticmigrationsenabled to True (that is, set as model has changed automatically update the database)

Add automaticmigrationdatalossallowed = True if you have deleted fields (you can accept data loss values during automatic migration)

Step three: In the Owndbcontext.

 Public owndbcontext ()             Base ("defaultconnection")        {                       Database.setinitializer (new Migratedatabasetolatestversion<owndbcontext, Own.model.migrations.configuration>());         }

PS: Some of the information in the check some of the third step, but I do not change this or the error changed to be able to

EF modifies model Automatic Update database

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.