Code First Migrations - Package Manager Console Host Version 5.9.1.0

Joann Liao 21 Reputation points
2021-04-18T20:35:35.577+00:00

Need your expertise. Please advise.

There's old table which already released to Production. It's already migrated and had related 2 recorded on the list of migrations ~IRM.SIMSDB\Migrations.

In recent, we want to make four changes on this table. including

  1. A column, A decimal type field, it needs to be changed its decimal points from 2 to 4
  2. B column B field needs to be removed from the table
  3. C column C field needs to be rename its name to C2 from C1
  4. Add a new column D as decimal type

all other data fields should stay the same.

So, please advise a best solution to migration this old table. e.g. Add-migration and Update-Database or make code change at Configuration set AutomaticMigrationsEnabled = true or something else.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
743 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,573 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,626 Reputation points
    2021-04-19T02:32:24.74+00:00

    Hi JoannLiao-4647,
    I suggest you use existing schema as a starting point.
    First create an initial blank migration, then you can add migrations for any new changes.
    Run the Add-Migration InitialCreate –IgnoreChanges command in Package Manager Console. This creates an empty migration with the current model as a snapshot.
    More details you can refer to this document.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentationto enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Joann Liao 21 Reputation points
    2021-04-19T20:52:15.457+00:00

    DuaneArnold-0443,

    I do have administrator role on Database. If U use DBA tools to do the migration, I am much concerns any possible confliction or violation at CODE-FIRST base the application to Start up?


  3. Joann Liao 21 Reputation points
    2021-04-20T17:35:40.303+00:00

    DuaneArnold-0443

    I am hands-on programming on SQL for many years. Last week, I did manually changed on SQL to manipulating the data field to be with decimal digit number from 2 to 5. I was wondering whether this approach is OK? Whether this kind of manual change via SQL , it may cause confliction with EF migration or not.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.