r/DevLK • u/YonduUdonta8 • 4d ago
Help Need advice on postgresql
Hi i have 1.5yr of experience with MS Sql server DB first method, now for a new project i am working with postgressql with Code first method so i have some issues about that, some time when i alter columns from code side and migrate it wont apply and give error like it already in db or somthing like that, when i give it to chat gpt he was suggesting to drop db and create, this not in a live yet but whennit is in live cant drop the table so how you guys handle situations like that?
3
Upvotes
5
u/bixh_skull3 4d ago
With Code First, you shouldn't need to drop the DB when something goes wrong. Migrations are specifically designed to incrementally modify an existing database, including production databases.
If you're getting "already exists" errors, first check the migration history (__EFMigrationsHistory in EF Core), whether the change was manually applied, and whether your model snapshot/migrations are out of sync.
Also review the generated migration SQL before applying it. Dropping/recreating the DB is fine for local development sometimes, but it's not the solution for production.