What is the equivalent of the -IgnoreChanges switch for entity-framework core in CLI?
In the absence of any other way, one can empty the Up and Down method blocks of the migration of all code and run database update.
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
My project has an existing database and we wanted to use migrations, since we do not have IgnoreChanges
in EFCore what i did was ran the command
Add-Migration -Name InitialMigration
in the package manager console
of visual studio, this created the InitialMigration.cs
file for me
And then I commented out the code in the Up function in the InitialMigration.cs
and ran the command update-database
in the package manager console
.
Doing this creates a table named dbo.__EFMigrationsHistory
in your database which keeps a track of your migrations.
Later when you add or remove the column, just run the Add-Migration command which will create a new migration for you make sure you validate the Up and Down function both to make sure everything looks ok and is as expected.
Once you validate, run the update-database
function which should run the new migration script for you.
For now this is how we went ahead with our implementation.