Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Entity Framework find Down() methods when my code migrations are behind my database migrations?

Let's say I'm a developer and I check out an old version of the code, so that my local database is "ahead", like

local db migrations: A -> B -> C -> D
    code migrations: A -> B

How I fix this is by running

Update-Database -TargetMigration -B

in PCM. As I understand, that runs

D.Down()
C.Down()

But where does EF find those methods if they're not in the code I've checked out? Are they in the [Model] columns of __MigrationHistory? I thought that column only stored the model, not migrations.

like image 536
Questionaire Avatar asked Apr 01 '26 22:04

Questionaire


1 Answers

There is no way that an old version of the code will know how to rollback the database. That information is held in the current version. You need to do Update-Database -TargetMigration -B using the current version then check out the old version.

like image 54
Colin Avatar answered Apr 04 '26 10:04

Colin