我有一个代码第一个MVC网站,我收到此错误,但我按照以下代码启用了自动迁移:
namespace KnightOwlMVC.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<KnightOwlMVC.Models.KnightOwlContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(KnightOwlMVC.Models.KnightOwlContext 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" }
// );
//
}
}
}
我已运行以下内容来更新数据库,但我仍然遇到同样的错误:
Update-Database -ConnectionStringName DefaultConnection
答案 0 :(得分:0)
最后通过一种非常简单的ditry方式修复此问题并删除数据库并重新开始。看作它是我开发的应用程序,但显然我不会推荐这种方式进行生产。