簡體   English   中英

模型支持 <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

最后,通過一種非常困難的嘗試來解決此問題,然后刪除數據庫並重新啟動。 既然它是我可以負擔的開發中的應用程序,但顯然我不推薦這種方式用於生產。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM