C
C#2mo ago
Kyiro

Migrating to EF Core migrations

Hello I'm rewriting a whole backend from TS into C# and I'm struggling at the migrations part after I scaffolded the db context. How would I start using the migrations system EF Core has without just nuking all the data?
9 Replies
Angius
Angius2mo ago
Just do?
Kyiro
Kyiro2mo ago
If I create an initial migration and try to update the db, it'd try to create every table even though they already exist.
Angius
Angius2mo ago
The data won't disappear unless you remove it Well, back up the database and try It's not like you're deving on production database anyway
Kyiro
Kyiro2mo ago
I did try that and it just errors I was thinking of messing with the migration history table but maybe there's a better way
Angius
Angius2mo ago
Could just empty the up and down methods in the migration file
Kyiro
Kyiro2mo ago
Then I'd have to run the old code to create a new db :/ They're not in sql files since it used kysely migrations
Angius
Angius2mo ago
I guess you could just add the first migration to the migrations table, then So EF thinks it's applied — and it technically is — and go from there
Kyiro
Kyiro2mo ago
So basically force it? I guess that's what I'll do if there's no better way
xandyMelo
xandyMelo2mo ago
I believe that you should create all entities and relationships, create a new schema, run the migrations and import the data, or just run the migrations in a new schema, and then point to the old schema, so for EF the db will be updated. I hope I helped
Want results from more Discord servers?
Add your server