C
C#3mo 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
Angius3mo ago
Just do?
Kyiro
KyiroOP3mo 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
Angius3mo 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
KyiroOP3mo 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
Angius3mo ago
Could just empty the up and down methods in the migration file
Kyiro
KyiroOP3mo 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
Angius3mo 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
KyiroOP3mo ago
So basically force it? I guess that's what I'll do if there's no better way
xandyMelo
xandyMelo3mo 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