I have some problem with migrations i can't understand. For example, I drop column from one of the tables(by this I mean drop field from class, of course, not dropping column from database manually), create new migration and update database. It works just fine. But when I run the application, it says that can't drop column that was already dropped after applying migration. Then I dropped _MigrationHistory Table and re-enabled migrations. Everything works fine again, while i'm not deleting one of dbcontext entities and not applying new migration. Update-database gives no errors. But when I run the application I got en error that dbo. can't be deleted because it doesn't exist. Of course it doesn't! Seems to me like my migration applyes twice, when I do update-database and when i run my appliration. Is it possible? AutomaticMigrationsEnabled is set to false. But we turned Automatic Migrations on before in the project. Maybe this is the reason? Pleace help me to solve this problem.
0
votes
Show exacly error message what you get.
– BWA
Cannot drop the table 'dbo.BillingPlan', because it does not exist or you do not have permission.
– el_konor
Perhaps the best is not to drop columns in the database. Perhaps the best is to delete the property in the Model's class and then do the migration (this migration is going to delete this column in the database).
– Jose Luis
Maybe i wrote not clear enough(not english speaking, sorry). I do all changes with DbContext classes, i don't change database manually, this is CODE first, i get it.
– el_konor
I try this and works for me. Show how you enable autmatic migrations. Maybe here is a reason.
– BWA
1 Answers
0
votes
Check the migrations history table in the database. I am working with EF7 and just had this happen to me. It seemed exactly like the migration was running a second time and therefore the very first table listed created an error. When I manually added the migration entry (migrationID and productversion) it seemed to clear up.