Migration with possible data loss

Asked

Viewed 735 times

1

When generating an update of db which results in possible data loss efcore shows the alert:

An Operation was scaffolded that may result in the Oss of data. Please review the Migration for Accuracy.

(In this specific case a field has been removed from the table)

When this occurs the structure of db is not amended.

To get around this situation I remove all migrations generated and Gero a new, with this, the new structure is successfully generated.
(As the app is not in production, so far I did not bother to recreate the db)

I would like to know the correct way to solve this kind of problem, ie, force table update even knowing of data loss. Or if there’s a better way to solve this kind of situation.

1 answer

1


There are two ways:

Remove-Migration

Removes the Migration with problems. Also removes the Snapshot database if applicable.

To undo the Migration:

Update-Database -Migration:NomeDeUmaMigrationAnterior

To undo all the Migrations, use:

Update-Database -Migration:0

Notice that Update-Database does not delete files from Migration. Approaches the solution you suggested in the question.

Looking into the mechanisms of Migrations automatic for EF Core, found this comment here. Apparently, the Microsoft team does not intend to implement support for Migrations automatic. In EF6, the configuration of Migrations automatic would be my suggestion.

  • So there’s no way Forçar atualização da tabela to delete a field or an index for example being required to recreate the entire database? If I delete all the migrations tables in production will surely get unnecessary fields/indexes correct @gypsy-Morrison-Mendez?

  • 1

    Correct. As I have recommended in recent months, everything that involves the Stack .NET Core is still unstable, in development, so the recommended is to wait and not make large and critical systems for production until the Stack is stable. Possibly new features will come to replace old features (such as data Loss and automatic migrations).

  • 1

    Addendum: in the future I will have to update this answer because the mechanisms that should remedy your doubt do not yet exist.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.