Ich habe ein paar Entitäten und deren Navigationseigenschaften umbenannt und eine neue Migration in EF 5 generiert. Wie bei Umbenennungen in EF-Migrationen üblich, wurden Objekte standardmäßig gelöscht und neu erstellt. Das wollte ich nicht, also musste ich die Migrationsdatei von Grund auf neu erstellen.Entity Framework Migrationen Umbenennen von Tabellen und Spalten
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");
}
Alles, was ich versuche zu tun, umbenennen dbo.ReportSections
-dbo.ReportPages
und dann dbo.ReportSectionGroups
zu dbo.ReportSections
. Dann muss ich die Fremdschlüsselspalte unter dbo.ReportPages
von Group_Id
zu Section_Id
umbenennen.
Ich lasse die Fremdschlüssel und Indizes, die die Tabellen verbinden, fallen, dann benenne ich die Tabellen und die Fremdschlüsselspalte, dann füge ich die Indizes und Fremdschlüssel wieder hinzu. Ich nahm an, dass dies funktionieren würde, aber ich bekomme einen SQL-Fehler.
Msg 15248, Ebene 11, Status 1, Prozedur sp_rename, Leitung 215 Entweder der Parameter @objname mehrdeutig oder das beanspruchte @objtype (Spalte) ist falsch. Msg 4902, Ebene 16, Status 1, Zeile 10 Das Objekt "dbo.ReportSections" kann nicht gefunden werden, da es nicht existiert oder Sie keine Berechtigungen haben.
Ich habe keine leichte Zeit herauszufinden, was hier falsch ist. Jede Einsicht wäre ungeheuer hilfreich.
Welche der obigen Zeilen ausfällt? Können Sie die Migration in SQL Server Profiler verfolgen und die entsprechende SQL überprüfen? –