Entity Framework Migraciones renombrando tablas y columnas
Renombré a un par de entidades y sus propiedades de navegación y generé una nueva Migración en EF 5. Como es habitual con los renombramientos en las migraciones de EF, de forma predeterminada, iba a eliminar objetos y volver a crearlos. Eso no es lo que quería, así que tuve que compilar el archivo de migración desde cero.
public override void Up()
{
DropForeignKey("dbo.ReportSectionGroups", "Report_Id", "dbo.Reports");
DropForeignKey("dbo.ReportSections", "Group_Id", "dbo.ReportSectionGroups");
DropForeignKey("dbo.Editables", "Section_Id", "dbo.ReportSections");
DropIndex("dbo.ReportSectionGroups", new[] { "Report_Id" });
DropIndex("dbo.ReportSections", new[] { "Group_Id" });
DropIndex("dbo.Editables", new[] { "Section_Id" });
RenameTable("dbo.ReportSections", "dbo.ReportPages");
RenameTable("dbo.ReportSectionGroups", "dbo.ReportSections");
RenameColumn("dbo.ReportPages", "Group_Id", "Section_Id");
AddForeignKey("dbo.ReportSections", "Report_Id", "dbo.Reports", "Id");
AddForeignKey("dbo.ReportPages", "Section_Id", "dbo.ReportSections", "Id");
AddForeignKey("dbo.Editables", "Page_Id", "dbo.ReportPages", "Id");
CreateIndex("dbo.ReportSections", "Report_Id");
CreateIndex("dbo.ReportPages", "Section_Id");
CreateIndex("dbo.Editables", "Page_Id");
}
public override void Down()
{
DropIndex("dbo.Editables", "Page_Id");
DropIndex("dbo.ReportPages", "Section_Id");
DropIndex("dbo.ReportSections", "Report_Id");
DropForeignKey("dbo.Editables", "Page_Id", "dbo.ReportPages");
DropForeignKey("dbo.ReportPages", "Section_Id", "dbo.ReportSections");
DropForeignKey("dbo.ReportSections", "Report_Id", "dbo.Reports");
RenameColumn("dbo.ReportPages", "Section_Id", "Group_Id");
RenameTable("dbo.ReportSections", "dbo.ReportSectionGroups");
RenameTable("dbo.ReportPages", "dbo.ReportSections");
CreateIndex("dbo.Editables", "Section_Id");
CreateIndex("dbo.ReportSections", "Group_Id");
CreateIndex("dbo.ReportSectionGroups", "Report_Id");
AddForeignKey("dbo.Editables", "Section_Id", "dbo.ReportSections", "Id");
AddForeignKey("dbo.ReportSections", "Group_Id", "dbo.ReportSectionGroups", "Id");
AddForeignKey("dbo.ReportSectionGroups", "Report_Id", "dbo.Reports", "Id");
}
Todo lo que estoy tratando de hacer es cambiar el nombredbo.ReportSections
adbo.ReportPages
y entoncesdbo.ReportSectionGroups
adbo.ReportSections
. Entonces necesito cambiar el nombre de la columna de clave externa endbo.ReportPages
desdeGroup_Id
aSection_Id
.
Estoy eliminando las claves externas y los índices que vinculan las tablas, luego renombro las tablas y la columna de la clave externa, luego vuelvo a agregar los índices y las claves externas. Asumí que esto iba a funcionar pero recibo un error de SQL.
Mensaje 15248, Nivel 11, Estado 1, Procedimiento sp_rename, Línea 215 El parámetro @objname es ambiguo o el @objtype (COLUMNA) reclamado es incorrecto. Msg 4902, Nivel 16, Estado 1, Línea 10 No se puede encontrar el objeto "dbo.ReportSections" porque no existe o no tiene permisos.
No me resulta fácil descubrir qué es lo que está mal aquí. Cualquier visión sería tremendamente útil.