I have an application with Entity Framework Code First.
In the table, I need to add a column. So I added it to the model and created the migration.
But during the migration, I would like to update existing records and add value for this new column. This value should be taken from the database (a constant field in my "Configuration" table).
But the default value should only be applied to existing records, not the next one.
How can I do this from my migration class?
My current migration class:
public override void Up() { var theDefaultValue = MyConstants.MyConstantParameterFromDatabase; AddColumn("MySchema.MyTable", "MyNewColumn", c => c.Decimal(nullable: false, precision: 18, scale: 2)); }
Edit: still look for a solution to update all existing entries (using value 0), but only after this migration ...
source share