Entity framework:the Model backing the ' context has changed since the database was created

Source: Internet
Author: User

1. When you do a project with code first, the database is generated and the database table structure is modified later. The problem occurs when you run again:

Entity framework:the model backing the ' ProductModel ' context has changed since the database was create

Workaround:

1. Open Current Project: Package Manager console

2. Input:enable-migrations-projectname ' ProductModel '-force

Explanation: ' ProductModel ', the name of the assembly where the EF framework model layer is located

See the results of the execution:

Checking If the context targets an existing database ...
Code first migrations enabled for Project ProductModel.

2. Open ' ProductModel ' and find migrations-configuration

Public Configuration ()
{
Automaticmigrationsenabled = true; (False, changed to TRUE)
automaticmigrationdatalossallowed = false; (if data is lost)
}

3. Input:update-database-projectname ' ProductModel '-force

See the results of the execution:

Specify the '-verbose ' flag to view the SQL statements being applied to the target database.
No pending explicit migrations.
Unable to update database to match the current model because there be pending changes and automatic migration is disabled . Either write the pending model changes to a code-based migration or enable automatic migration. Set dbmigrationsconfiguration.automaticmigrationsenabled to True to enable automatic migration.
You can use the add-migration command to write the pending model changes to a code-based migration.

4. If a problem is found, rebuild the solution

Photos below when operating:

Entity framework:the Model backing the "context has changed since the database was created

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.