Reputation: 2855
I make a mistake. I delete some row in table __MigrationHistory
in my database.
and now when I run my project I force this error:
ALTER TABLE DROP COLUMN failed because column 'xxx' does not exist in table 'yyy'.
How can I solved this problem?
Upvotes: 6
Views: 20005
Reputation: 56
I got this one using EF Core 3.1.1 while I was trying to add a new field to a table.
I didn't delete entries in the MigrationHistory table but I reverted the last migration, removed the generated migration files and generated them again with 'add migration'. Then I noticed the new Up and Down methods of the migrations where using AlterColumn instead of AddColumn and RemoveColumn. I got the code from the previous Up and Down methods and that solved it.
Upvotes: 0
Reputation: 45
Here is more details since I had the same issue and this Question was help full: For whatever reason if you get this error: ALTER TABLE DROP COLUMN failed because column 'xxx' does not exist in table 'yyy'. Do this: manually update the table in the database.
Upvotes: 1
Reputation: 2855
OK, finally I solved my problem.
I added field 'xxx' to table 'yyy' manually in my database.
Upvotes: 3
Reputation: 12304
Add a new migration to re-synchronize:
add-migration MissingXXX -IgnoreChanges // tells EF to just take a snapshot
update-database
Now you are back in sync and can continue with future model changes.
Upvotes: 11
Reputation: 1
Why not altering your table to recreat the missing column ? And then try to drop your table again :)
Upvotes: 0