前期修改数据库表结构,数据库已经更动

一.应用code first
做项目时,数据库已经转移,中期修改数据库表结构。再度运转时现身转手标题:

壹.利用code first
做项目时,数据库已经变化,早先时期修改数据库表结构。再度运维时出现转手难点:

Entity Framework : The model backing the ‘ProductModel’ context has changed since the database was create

解决措施:

一.展开当前项目中的:程序包管理器调节台

皇冠现金app 1

2.输入:enable-migrations -ProjectName
‘ProductModel’ -Force       

解释:’ProductModel‘,ef框架model层所在程序集名称,不明了请看上边操作时图片

见状举行结果:

Checking if the context targets
an existing database…
Code First Migrations enabled
for project ProductModel.

 

2.打开 ’ProductModel‘,找到Migrations-Configuration

 

public Configuration()
{
    AutomaticMigrationsEnabled = true;    
(原来为false,改为true)
              AutomaticMigrationDataLossAllowed = false;  
(是还是不是丢数据)
}

 

3.输入:update-DataBase -ProjectName
‘ProductModel’ -Force

看样子进行结果:

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 are 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.

肆.假设发掘有题目,重新生成化解方案

上边时操作时的照片:

皇冠现金app 2

皇冠现金app 3

 

Entity Framework : The model backing the ‘ProductModel’ context has changed since the database was create

消除办法:

一.开荒当前项目中的:程序包管理器调控台

皇冠现金app 4

皇冠现金app,2.输入:enable-migrations -ProjectName
‘ProductModel’ -Force       

讲解:’ProductModel‘,ef框架model层所在程序集名称,不知道请看上面操作时图片

见到实行结果:

Checking if the context targets
an existing database…
Code First Migrations enabled
for project ProductModel.

 

2.打开 ’ProductModel‘,找到Migrations-Configuration

 

public Configuration()
{
    AutomaticMigrationsEnabled = true;    
(原来为false,改为true)
              AutomaticMigrationDataLossAllowed = false;  
(是不是丢数据)
}

 

3.输入:update-DataBase -ProjectName
‘ProductModel’ -Force

看来实行结果:

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 are 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.即使开掘有失水准,重新生成化解方案

上边时操作时的照片:

皇冠现金app 5

皇冠现金app 6