Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 将Web应用程序和DB发布到Azure—支持';应用程序上下文';自创建数据库以来,上下文已更改_Asp.net Mvc_Azure Sql Database_Azure Web App Service - Fatal编程技术网

Asp.net mvc 将Web应用程序和DB发布到Azure—支持';应用程序上下文';自创建数据库以来,上下文已更改

Asp.net mvc 将Web应用程序和DB发布到Azure—支持';应用程序上下文';自创建数据库以来,上下文已更改,asp.net-mvc,azure-sql-database,azure-web-app-service,Asp.net Mvc,Azure Sql Database,Azure Web App Service,我正在将我的应用程序从本地迁移到Azure,并遇到以下错误: 支持“ApplicationDbContext”上下文的模型自 数据库已创建 我的数据库由ASP.net标识字段和我添加的一些其他表组成: 初始迁移: namespace WebApplication12.Migrations { using System; using System.Data.Entity.Migrations; public partial class init : DbMigratio

我正在将我的应用程序从本地迁移到Azure,并遇到以下错误:

支持“ApplicationDbContext”上下文的模型自 数据库已创建

我的数据库由ASP.net标识字段和我添加的一些其他表组成:

初始迁移:

namespace WebApplication12.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.AspNetRoles",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Name = c.String(nullable: false, maxLength: 256),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.Name, unique: true, name: "RoleNameIndex");

            CreateTable(
                "dbo.AspNetUserRoles",
                c => new
                    {
                        UserId = c.String(nullable: false, maxLength: 128),
                        RoleId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.UserId, t.RoleId })
                .ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);

            CreateTable(
                "dbo.AspNetUsers",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Email = c.String(maxLength: 256),
                        EmailConfirmed = c.Boolean(nullable: false),
                        PasswordHash = c.String(),
                        SecurityStamp = c.String(),
                        PhoneNumber = c.String(),
                        PhoneNumberConfirmed = c.Boolean(nullable: false),
                        TwoFactorEnabled = c.Boolean(nullable: false),
                        LockoutEndDateUtc = c.DateTime(),
                        LockoutEnabled = c.Boolean(nullable: false),
                        AccessFailedCount = c.Int(nullable: false),
                        UserName = c.String(nullable: false, maxLength: 256),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.UserName, unique: true, name: "UserNameIndex");

            CreateTable(
                "dbo.AspNetUserClaims",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserId = c.String(nullable: false, maxLength: 128),
                        ClaimType = c.String(),
                        ClaimValue = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);

            CreateTable(
                "dbo.AspNetUserLogins",
                c => new
                    {
                        LoginProvider = c.String(nullable: false, maxLength: 128),
                        ProviderKey = c.String(nullable: false, maxLength: 128),
                        UserId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);

        }

        public override void Down()
        {
            DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
            DropIndex("dbo.AspNetUserLogins", new[] { "UserId" });
            DropIndex("dbo.AspNetUserClaims", new[] { "UserId" });
            DropIndex("dbo.AspNetUsers", "UserNameIndex");
            DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" });
            DropIndex("dbo.AspNetUserRoles", new[] { "UserId" });
            DropIndex("dbo.AspNetRoles", "RoleNameIndex");
            DropTable("dbo.AspNetUserLogins");
            DropTable("dbo.AspNetUserClaims");
            DropTable("dbo.AspNetUsers");
            DropTable("dbo.AspNetUserRoles");
            DropTable("dbo.AspNetRoles");
        }
    }
}
最新迁移:

namespace WebApplication12.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class paymentsmodel : DbMigration
    {
        public override void Up()
        {
        }

        public override void Down()
        {
        }
    }
}
我在StackOverflow的整个过程中都在研究这个问题,但我仍然完全不知所措。当我查看迁移时,最初的迁移包括所有ASP.net标识表,但没有我添加的其他表。当我运行另一个迁移时,它是空的

但我没有添加任何其他表。当我运行另一个迁移时,它是空的

确保不更改表中的任何模型。如果您有更改模型,则需要使用
addmigration
命令和
updatedatabase

并在发布网站时单击“设置”中的“执行代码优先迁移(在应用程序启动时运行)”,这可能会更新对azure的更改

此外,您还可以从本地的SQL Server对象资源管理器中删除在迁移历史记录表中创建的记录

全局.asax中的
应用程序启动()
中添加以下行:

Database.SetInitializer<Models.YourDbContext>(null);
Database.SetInitializer(null);

请阅读以下文章: