I am doing data-migration for my project. But I have one question, for example:
I have Book table with following fields:
ID Name Color
1 Java red
2 MVC blue
3 .Net blue
I tried to change the name of field from “Color” to “BookColor” using Code First tech. But after migration the table looked like this:
ID Name BookColor
1 Java null
2 MVC null
3 .Net null
I lost my field values. How can I make sure that all value are transfered?
I’m using Entity Framework with MVC3
EDIT This is my DBMigration Class:
public partial class AddCreative : DbMigration
{
public override void Up()
{
AddColumn("Authors", "Names", c => c.String(maxLength: 4000));
DropColumn("Authors", "Name");
}
public override void Down()
{
AddColumn("Authors", "Name", c => c.String(maxLength: 4000));
DropColumn("Authors", "Names");
}
}
I have changed Name to Names after changing (I lost my data in name field).
I had no problems using the following:
First, setup the migrations:
Then we setup the migrations class to perform the rename:
Next, make a call to
Update-Databaseso we can perform the changes:And voila, it’s renamed and the data is retained.