自数据库创建以来,支持 <Database> 上下文的模型已更改。考虑使用代码优先迁移来更新数据库
The model backing the <Database> context has changed since the database was created. Consider using Code First Migrations to update the database
我有一个代码优先 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
最终通过一种非常低级的方式并删除数据库并重新开始来解决这个问题。鉴于它是一个开发中的应用程序,我可以负担得起,但显然我不会推荐这种方式用于生产。
我有一个代码优先 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
最终通过一种非常低级的方式并删除数据库并重新开始来解决这个问题。鉴于它是一个开发中的应用程序,我可以负担得起,但显然我不会推荐这种方式用于生产。