Migrações de estrutura de entidades renomeando tabelas e colunas
Renomei algumas entidades e suas propriedades de navegação e gerou uma nova Migração na EF 5. Como é comum em renomeações em migrações de EF, por padrão, elas seriam descartadas e recriadas. Isso não é o que eu queria, então eu praticamente tive que construir o arquivo de migração a partir do zero.
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");
}
Tudo o que estou tentando fazer é renomeardbo.ReportSections
paradbo.ReportPages
e depoisdbo.ReportSectionGroups
paradbo.ReportSections
. Então eu preciso renomear a coluna de chave estrangeiradbo.ReportPages
deGroup_Id
paraSection_Id
.
Estou soltando as chaves estrangeiras e os índices que ligam as tabelas, então estou renomeando as tabelas e a coluna de chave estrangeira, então estou adicionando os índices e chaves estrangeiras novamente. Eu assumi que isso ia funcionar, mas estou recebendo um erro de SQL.
Msg 15248, nível 11, estado 1, procedimento sp_rename, linha 215 O parâmetro @objname é ambíguo ou o @objtype reivindicado (COLUMN) está errado. Msg 4902, nível 16, estado 1, linha 10 Não é possível localizar o objeto "dbo.ReportSections" porque ele não existe ou você não tem permissões.
Não estou tendo tempo fácil para descobrir o que está errado aqui. Qualquer insight seria tremendamente útil.