'An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy. happens after Update-database has no change

I performed an Update-database command and received the message that there were no changes and the database was up to date.

Then after subsequently issuing the add-migration command to create a new migration file I received this message in the console with an AlterColumn migration added to my migration file.

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

It appears as though there was a prior column alteration to change a column data type to a table in the database. But my migration was totally unrelated to the table or field change.

My question is why wouldn't that change have been picked up during the update-database command instead of a scaffold into my new migration file???

Maybe its my personal paranoia kicking in but I've never seen a change implemented by EF Core Code-First "after" Update-Database reports "no changes"



Solution 1:[1]

My question is why wouldn't that change have been picked up during the update-database command instead of a scaffold into my new migration file???

Because update-database applies the latest migration, not the other way around. You make some changes, run add-migration XXXXX which instructs EF to find any changes (using your context snapshot) and make a migration file. Nothing happens to the database until you apply the migration using update-database. If you make any more model/schema changes before applying the migration to the database, they won't be added to the pending migration automatically.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Victor Sand