❔ EF Migration successful but nothing changes
I can see that the commands resulted OK, the migration has the new columns and the database has the new migration in it's history
Yet the new columns in the model have not been added to the database
I have made migrations many times in this project without problems, attaching relevant pictures and migration (Newest migration is "addSuccessIncrement14" and a new column is "waitDescription")
I have tried Clean/Rebuild, and checked GPTs suggestions
33 Replies
You attached the wrong file
can you show the generated migration file, not the one containing the snapshot for that state
It contains empty Up/down-methods so EF didn't detect any changes to generate the migration
right
thats why your migration does nothing
as to WHY ef didnt detect any changes, I cant tell
try to remove that migration and check the snapshot
does it still contain the "new" column?
then its not new
@Pobiega Yes the snapchat still contains the "new" column after deletion
Altough there was no migrations that contain the addition of the new column
Before this, I tried to temporarily change the connection string to another local db, and that db has the new column
But not one migration file with up/down contains the name of the column
I added another property called testString and migrated, now that column appears in migration/db but not the other new properties
curious.
Yes right
Recognizing new properties but not old ones
the snapshot isnt derived from the actual database, its just a... continous evolution of your model
Everything is the same, public and whatnot
It has to be relating to that temporary copy of the db, that contained all the new columsn
Because those will not be added to the original db
I think this is a case of software not working as intended, but I should not cast doubt so soon on something so vigorously tested
I should learn to read these, but maybe this will lead to a report because I can't see any suggestions for making EF recognize these model changes that I have not yet tried
I frankly doubt it, EF is used by millions
it might seem weird, but its almost always user error somehow 🙂
have you ever added then removed migrations before, and not via the
ef migrations remove
command?
that could easily "corrupt" your snapshotif you deleted manually already executed migration then migration table is corrupted. That's probably what's going on, and now it cannot find your changes
my question would be. Is it possible for you to reset your migration?
exactly
the easiest would be to reset whole history "start" over with one big migration
Thank you I think you are right
Someone(absolutely not me) has deleted without proper command
you could also fix your snapshot manually, via "snapshot surgery"
if that's production code, then you need to manipulate changes in db manually
I'm trying to repair as we speak
its annoying, but not impossible, to manually edit the snapshot
alterantively, make a blank DB, run the latest migration, take that snapshot, go back to your normal code, paste snapshot
It's in development
and pray to god
So I think easiest solution is to start over like you say
Sorry god is not on my side
okok, is this running code on production?
I mean if you have any migration on production
No there is nothing in prod
then it's far better to repair
ah, delete all and start over 😄
if you are fine with resetting your databases, you could just delete your DBs and all migrations
and generate a brand new "initial" migration
excatly
it's the quickest solution
also, just a heads up
This might cause a headache for the people sharing my repository but I will tell them first
in a large EF core app with many migrations, compiling the migratons is a HUGE part of your build time
so we actually script and merge migrations every now and then
its a nightmarish process, but having 400+ migrations that sum up to ~500K lines of code to compile is.... 😄
just tell them to drop and create db after pull
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.