我的種子方法在我的本地機器上運行時工作得很好,但是當我將代碼推送到appharbor時,種子無法正常工作。種子方法在本地機器上工作,但不是appharbor
這是我的連接字符串:
<connectionStrings>
<add name="FinalProjectContext" connectionString="Data Source=.\SQLEXPRESS;User
Id=user;Password=pass;initial catalog=MyContextDB;"
providerName="System.Data.SqlClient" />
</connectionStrings>
我種方法是Configuration
文件遷移內:
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(MyContext context)
{
//add data
}
我打電話從上下文類我的種子法,裏面的OnModelCreating
:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, Configuration>());
}
編輯
AppHarbor支持SQLExpress? – JayC
@JayC我不知道,但不是appharbor應該替換我的連接字符串,我只需要在sql別名字段中輸入我的上下文名稱? – SOfanatic
@SOfanatic我認爲你需要擁有正確的連接名稱,併爲MSSQL服務器設置「app/plugin」(AppHarbor稱之爲)。只有這樣他們纔會替換連接字符串。對此的快速測試是嘗試打印'ConfigurationManager.ConnectionStrings [「MyContext」] .ConnectionString'(使用Response.Write或某個控制器/視圖)。 – Alxandr