我已經使用ButBucket Git回購在Microsoft Azure(Web App)中設置了連續部署。 Code First Migrations在我的計算機上運行良好,它創建表並將它們播種,但是當我同步分支時,遷移的種子方法未在Azure上運行。Azure持續部署 - 代碼優先遷移播種問題(MVC 5)
因此,Azure從BitBucket獲取更改,根據需要創建表,但不運行種子方法(每個表仍爲空)。
您是否可以建議一個解決方案,以便在應用新遷移時自動運行Azure上的Seed方法(或每次Azure從BitBucket構建時(如果這是唯一的解決方案)?
附加信息:
- MigrationHistory表包含遷移,所以它們運行。
- 我已經設置了AutomaticMigrationsEnabled = true;但問題仍然存在
- 在Azure上還有這是建立和遷移的Web應用程序,而這是在ConnectionString引用Web.config中
Configuration.cs
internal sealed class Configuration : DbMigrationsConfiguration<MyInsidR.Models.ApplicationDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
ContextKey = "MyInsidR.Models.ApplicationDbContext";
}
protected override void Seed(ApplicationDbContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
context.Prophecies.AddOrUpdate(p => p.ID,
new Prophecy() { ID = 1, Text = "Fűben iszogatós, sírva nevetős."}
);
context.Interesteds.AddOrUpdate(x => x.ID,
new Interested() { ID = 1, Email = "[email protected]", FirstName = "Elek", LastName = "Teszt", RegistrationDate = DateTime.Now }
);
var tag1 = new Tag() { ID = 1, Name = "Karaoke", ApplyTo = TagApplication.All, Type = TagType.Games };
var tag3 = new Tag() { ID = 3, Name = "4 rooms", ApplyTo = TagApplication.All, Type = TagType.Misc };
var tag4 = new Tag() { ID = 4, Name = "Helipad", ApplyTo = TagApplication.All, Type = TagType.Vip };
context.Tags.AddOrUpdate(x => x.ID,
tag1, tag3, tag4
);
var indicatorIcon1 = new IndicatorIcon() { ID = 1, VisualClass = IndicatorIcon.VisualClassType.Hidden, Name = "No Indicator Icon", Description = "Nothing special, just a regular place or event." };
var indicatorIcon2 = new IndicatorIcon() { ID = 2, VisualClass = IndicatorIcon.VisualClassType.Fire, Name = "Hot", Description = "This place or event is very popular at the moment. There are big parties and a big fuss around it." };
context.IndicatorIcons.AddOrUpdate(x => x.ID,
indicatorIcon1, indicatorIcon2
);
AddUserAndRole(context);
}
bool AddUserAndRole(ApplicationDbContext context)
{
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var identityResult = roleManager.Create(new IdentityRole("Admin"));
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
var user = new ApplicationUser()
{
UserName = "[email protected]",
};
identityResult = userManager.Create(user, "Qwertz1234!");
if (identityResult.Succeeded == false)
return identityResult.Succeeded;
identityResult = userManager.AddToRole(user.Id, "Admin");
return identityResult.Succeeded;
}
}
SQL數據庫
(我發現只有從Visual Studio直接部署的種子方法問題相關的問題和解決方案,但這不是我想要去的方式。但我認爲MVC項目中的代碼第一次遷移是最乾淨的解決方案,如果它在我的本地計算機上工作)
你解決了這個問題嗎? – erwineberhard
是的,但我不得不修改代碼,而不是我以前的概念來修復它在Azure UI或某些配置文件中。詳情請見我的回答! –