Gary Frewin
Gary Frewin

Reputation: 565

Resolving Alter Table drop Column failed because column does not exist in docker fresh update

I'm a tad confused. I have a EF6 project I've been working on. I added a column to a model and then later removed it as I realised I didn't need it. I also removed it from the migration file and the map file... basically there is no reference anywhere in the project to this column ever having existed.

I'm working using a docker SQL server db which I essentially completely delete and reseed from scratch for testing. So, the database also has no record of this column ever having existed either. However, when i spin up a fresh empty docker sql server, and run update-database I get a message of

'ALTER TABLE DROP COLUMN failed because column 'ColumnName' does not exist in table 'TableName'.

I've gone through the migration files, the table map files and even ran a search of every file in the entire project and there is zero mentions of ColumnName... I'm baffled how the update-datebase method even knoww the column ever existed.

Is there some hidden reference to this column that I need to remove?

EDIT: So it appears to be part of the automatic_migrations... if I run it with -verbose I can see the SQL is referencing the non-existant column name. I just don't know why, or how I can stop it. Can I edit/reset the automatic migration script?

Upvotes: 0

Views: 887

Answers (1)

Gary Frewin
Gary Frewin

Reputation: 565

Found an answer eventually to do with the model being out of sync. Rescaffolding the latest migration sorted it out.

METHOD 2 in the following stack thread solved it for me.

Even though model matches I am getting - Unable to update database to match the current model

Upvotes: 0

Related Questions