Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8201855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:57:33+00:00 2026-06-07T06:57:33+00:00

I am doing data-migration for my project. But I have one question, for example:

  • 0

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:57:34+00:00Added an answer on June 7, 2026 at 6:57 am

    I had no problems using the following:

    First, setup the migrations:

    PM> Enable-Migrations
    PM> Add-Migration RenameBookColorColumn
    

    Then we setup the migrations class to perform the rename:

    public class RenameBookColorColumn : DbMigration
    {
        public override void Up()
        {
            this.RenameColumn("Books", "Color", "BookColor");
        }
        public override void Down()
        {
            this.RenameColumn("Books", "BookColor", "Color");
        }
    }
    

    Next, make a call to Update-Database so we can perform the changes:

    PM> Update-Database -Verbose
    Using NuGet project 'Example'.
    Using StartUp project 'ExampleTest'.
    Target database is: 'ExampleContext' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
    Applying explicit migrations: [201207051400010_RenameBookColorColumn].
    Applying explicit migration: 201207051400010_RenameBookColorColumn.
    EXECUTE sp_rename @objname = N'Books.Color', @newname = N'BookColor',
    @objtype = N'COLUMN' [Inserting migration history record]
    

    And voila, it’s renamed and the data is retained.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently doing a project in which I have to request data from
I already have some simple project with one migration script: # --- !Ups create
I'm doing a data migration at the moment and one task I'm doing is
currently, I'm doing a bit of a data migration between one db to another
I have a table that holds data received from a thirdparty via an api
I'm doing a data migration in SQL Server 2008 R2. I'm a SQL-Server noob,
I am in the process of doing a data migration from OpenCart into Drupal
I'm doing a data migration at the moment of a subset of data from
I am experiencing big time and computing power challenges when doing big data migration
I am doing a database migration work. I have to copy a database in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.