Migration with possible data loss

1

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

  

An operation was scaffolded that may result in the loss of data.   Please review the migration for accuracy.

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

When this occurs the db structure is not changed.

To get around this situation I remove all generated migrations and generate a new one, with this, the new structure is generated successfully.
(As the application is not in production, so far I was not worried about re-creating db )

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

    
asked by anonymous 11.01.2017 / 02:43

1 answer

1

There are two ways:

Remove-Migration

Remove the Migration with problems. Also remove the Snapshot from the database if applicable.

To undo Migration :

Update-Database -Migration:NomeDeUmaMigrationAnterior

To undo all Migrations , use:

Update-Database -Migration:0

Note that Update-Database does not delete Migration files. Approach the solution you suggested in the question.

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

    
11.01.2017 / 04:46