I renamed a couple of objects and their navigation properties and created a new migration to EF 5. As usual, with renaming in EF transitions, by default he was going to delete objects and recreate them. This is not what I wanted, so I pretty much had to create a migration file from scratch.
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"); }
All I'm trying to do is rename dbo.ReportSections to dbo.ReportPages and then dbo.ReportSectionGroups to dbo.ReportSections . Then I need to rename the foreign key column to dbo.ReportPages from Group_Id to Section_Id .
I delete the foreign keys and indexes linking the tables together, then I rename the tables and the foreign key column, then add the indexes and foreign keys again. I assumed this would work, but I am getting an SQL error.
Msg 15248, level 11, state 1, sp_rename procedure, line 215 Either the @objname parameter is ambiguous, or the declared @objtype code (COLUMN) is incorrect. Msg 4902, Level 16, State 1, Line 10 The object "dbo.ReportSections" cannot be found because it does not exist or you do not have permissions.
It’s not easy for me to figure out what’s wrong here. Any insight would be extremely helpful.