I do not know if this is the correct approach but if I:
- Disable automatic migrations in ApplicationDbContext, then
- Add a migration for it and comment out the tables in question, all works.
I would appreciate it if someone will tell me if this is the correct approach:
namespace Data.Migrations_ApplicationDbContext
{
using System;
using System.Data.Entity.Migrations;
public partial class ApplicationDbContext : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.App_DbMenuRoles",
c => new
{
Id = c.Long(nullable: false, identity: true),
FK_RoleId = c.Long(nullable: false),
FK_DbMenuId = c.Long(nullable: false),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.App_CustomRoles", t => t.FK_RoleId, cascadeDelete: true)
.ForeignKey("dbo.App_DbMenus", t => t.FK_DbMenuId, cascadeDelete: true)
.Index(t => t.FK_RoleId)
.Index(t => t.FK_DbMenuId);
//CreateTable(
// "dbo.App_CustomRoles",
// c => new
// {
// Id = c.Long(nullable: false, identity: true),
// Name = c.String(),
// })
// .PrimaryKey(t => t.Id);
//CreateTable(
// "dbo.App_CustomUserRoles",
// c => new
// {
// Id = c.Long(nullable: false, identity: true),
// UserId = c.Long(nullable: false),
// RoleId = c.Long(nullable: false),
// CustomRole_Id = c.Long(),
// })
// .PrimaryKey(t => t.Id)
// .ForeignKey("dbo.App_CustomRoles", t => t.CustomRole_Id)
// .Index(t => t.CustomRole_Id);
CreateTable(
"dbo.App_DbMenus",
c => new
{
Id = c.Long(nullable: false, identity: true),
Title = c.String(nullable: false),
PrimaryUrl = c.String(nullable: false),
SecondaryUrl = c.String(),
TertiaryUrl = c.String(),
FK_ParentId = c.Long(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.App_DbMenus", t => t.FK_ParentId)
.Index(t => t.FK_ParentId);
}
public override void Down()
{
DropForeignKey("dbo.App_DbMenus", "FK_ParentId", "dbo.App_DbMenus");
DropForeignKey("dbo.App_DbMenuRoles", "FK_DbMenuId", "dbo.App_DbMenus");
DropForeignKey("dbo.App_DbMenuRoles", "FK_RoleId", "dbo.App_CustomRoles");
DropForeignKey("dbo.App_CustomUserRoles", "CustomRole_Id", "dbo.App_CustomRoles");
DropIndex("dbo.App_DbMenus", new[] { "FK_ParentId" });
DropIndex("dbo.App_CustomUserRoles", new[] { "CustomRole_Id" });
DropIndex("dbo.App_DbMenuRoles", new[] { "FK_DbMenuId" });
DropIndex("dbo.App_DbMenuRoles", new[] { "FK_RoleId" });
DropTable("dbo.App_DbMenus");
DropTable("dbo.App_CustomUserRoles");
DropTable("dbo.App_CustomRoles");
DropTable("dbo.App_DbMenuRoles");
}
}
}