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