The documentation is not very helpful - just a list of function signatures, of which the simplest is:
public virtual OperationBuilder DeleteData (string table, string keyColumn, object keyValue, string schema = null);
I am fairly sure I can work out what goes in table, keyColumn and schema, but what value should I put in keyValue if I want to delete all rows?
Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. So, deleting migration files does not affect the data in the database.
Delete the row corresponding to your migration that you want to unapply (Say "yes" to the warning, if prompted). Run "dotnet ef migrations remove" again in the command window in the directory that has the project. json file. Alternatively, run "Remove-Migration" command in the package manager console.
doesn't look like the DeleteData operations are designed to allow for a delete everything in the table operation. EF uses the keyColumn and keyValue to determine what to delete, i.e. where keyColumn = keyValue. I would recommend using something like this:
migrationBuilder.Sql("DELETE FROM [table]", true);
https://github.com/dotnet/efcore/blob/main/src/EFCore.Relational/Migrations/Operations/DeleteDataOperation.cs
https://github.com/dotnet/efcore/blob/main/src/EFCore.Relational/Migrations/MigrationBuilder.cs (about line 1400)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With