sql - Renaming a table and a foreign key fails using ef6 -


i use ef6 , code first migrations. have 2 tables

public class team {      public int id { get; set; }      public string name { get; set; } }  public class teammember {      public int id { get; set; }      public string name { get; set; }      public team team { get; set; }      public int teamid { get; set; }  } 

i want rename teammember teammemberdeprecated , add new tabled named teammember differences table layout. main reason creating new table data. want save of data in current teammember table need rename it, , want transfer specific data need new teammember table.

when add migration looks this

renametable(name: "dbo.teammember", newname: "teammemberdeprecated"); 

what doesn't change name of foreign key property fk_dbo.teammember_dbo.team_teamid fk_dbo.teammemberdeprecated_dbo.team_teamid.

this presents problem when go create new teammember table because foreign key fk_dbo.teammember_dbo.team_teamid exists in database.

i tried dropping foreign key , renaming it, doesn't , when run migration -verbose see why it's expecting foreign key null. want keep data, perhaps approach wrong.

any suggestions welcome, thanks.

let ef rename table, go sql management studio , manually rename foreign keys.

go ef, make changes, run migration , let ef create new foreign keys

don't forget backup db


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -