人妻无码中文字幕永久在线,99RE6这里有精品热视频,国产成人综合色就色综合 ,蜜臀av在线观看

新聞建站cms系統(tǒng)、政府cms系統(tǒng)定制開(kāi)發(fā)

廣州網(wǎng)站建設(shè)公司-閱速公司

asp.net新聞發(fā)布系統(tǒng)、報(bào)紙數(shù)字報(bào)系統(tǒng)方案
/
http://www.jdki.com.cn/
廣州網(wǎng)站建設(shè)公司
您當(dāng)前位置:首頁(yè)>ASP.NET MVC

ASP.NET MVC

如何在asp.net mvc 3.0使用Nuget更新數(shù)據(jù)庫(kù)?

發(fā)布時(shí)間:2014/1/10 11:32:32  作者:Admin  閱讀:561  

廣告:

asp.net mvc3.0我們就需要更新數(shù)據(jù)庫(kù),方法是:

1.安裝VS的Nuget。打開(kāi)Nuget控制臺(tái),輸入Enable-Migrations啟用數(shù)據(jù)庫(kù)遷移。如果已經(jīng)啟用,控制臺(tái)會(huì)提示“Migrations have already been enabled in project '***'. To overwrite the existing migrations configuration, use the -Force parameter.”

2.標(biāo)記遷移點(diǎn),輸入Add-Migration ***,星號(hào)為遷移點(diǎn)名稱,可自定義。

3.輸入U(xiǎn)pdate-Database完成更新。

此時(shí)再執(zhí)行程序,則不會(huì)再出現(xiàn)報(bào)錯(cuò),數(shù)據(jù)庫(kù)也更新完畢了。如果想回退到某一次的遷移點(diǎn),只需要在Nuget控制臺(tái)中輸入 Update-Database –TargetMigration:"***" 星號(hào)為遷移點(diǎn)名稱。另外可以通過(guò)Script參數(shù)生成腳本,例如Update-Database -Script -SourceMigration:"**" -TargetMigration:"**" 這樣就會(huì)生成一個(gè)sql腳本而不是直接更新數(shù)據(jù)庫(kù)。

當(dāng)然,如果覺(jué)得操作控制臺(tái)的指令太多不方便,可以使用自動(dòng)遷移功能。方法如下:

1.打開(kāi) Migrations文件夾下的Configuration.cs,修改代碼為

public Configuration()

{

AutomaticMigrationsEnabled = true;

}

2.如果需要更新數(shù)據(jù)庫(kù),只需要在Nuget控制臺(tái)輸入U(xiǎn)pdate-Database -Verbose即可,如果提示“Automatic migration was not applied because it would result in data loss”(不能自動(dòng)遷移,會(huì)導(dǎo)致數(shù)據(jù)丟失) ,則在Update-Database 后面加 -Force參數(shù)即可。注意,這樣并不會(huì)引起數(shù)據(jù)丟失。

PM> Update-Database -Force

Specify the '-Verbose' flag to view the SQL statements being applied to the target database.

No migrations configuration type was found in the assembly 'TopWin.Etone.Web'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).

 

廣告:

相關(guān)文章
asp.net mvc
Nuget
cms新聞系統(tǒng)購(gòu)買(mǎi)咨詢
掃描關(guān)注 廣州閱速軟件科技有限公司
掃描關(guān)注 廣州閱速科技