Entity Framework Migrations benennt Tabellen und Spalten um
Ich habe ein paar Entitäten und ihre Navigationseigenschaften umbenannt und in EF 5 eine neue Migration generiert. Wie bei Umbenennungen in EF-Migrationen üblich, löschte es standardmäßig Objekte und erstellte sie neu. Das wollte ich nicht, also musste ich die Migrationsdatei von Grund auf neu erstellen.
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");
}
Ich versuche nur umzubenennendbo.ReportSections
zudbo.ReportPages
und danndbo.ReportSectionGroups
zudbo.ReportSections
. Dann muss ich die Fremdschlüsselspalte weiter umbenennendbo.ReportPages
vonGroup_Id
zuSection_Id
.
Ich lösche die Fremdschlüssel und Indizes, die die Tabellen miteinander verbinden, benenne die Tabellen und die Fremdschlüsselspalte um und füge dann die Indizes und Fremdschlüssel erneut hinzu. Ich nahm an, dass dies funktionieren würde, aber ich erhalte einen SQL-Fehler.
Meldung 15248, Ebene 11, Status 1, Prozedur sp_rename, Zeile 215 Entweder ist der Parameter @objname nicht eindeutig, oder der beanspruchte @objtyp (COLUMN) ist falsch. Meldung 4902, Ebene 16, Status 1, Zeile 10 Das Objekt "dbo.ReportSections" kann nicht gefunden werden, da es nicht vorhanden ist oder Sie keine Berechtigungen haben.
Es fällt mir nicht leicht, herauszufinden, was hier falsch ist. Jeder Einblick wäre enorm hilfreich.