Hi all, We are running into some prisma migrate i...
# prisma-migrate
t
Hi all, We are running into some prisma migrate issues on our production DB. The issue first started on our development DB when prisma returned the typical “Drift Detected” error. We fixed this by reseting the DB. We attempted to push our latest prisma changes to our prod DB by running
prisma migrate deploy
but that too resulted in errors such as this one…
Copy code
DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42704"), message: "constraint \"CustomField_memberId_fkey\" of relation \"CustomField\" does not exist", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("tablecmds.c"), line: Some(10987), routine: Some("ATExecDropConstraint") }
We tried manually fixing the errors one by one, but we didn’t get any where with it. No matter what we did,
migrate deploy
would never succeed. That led us to try to start from a clean slate. We tried the following…. 1. we first duplicated our production database for testing purposes. 2. we deleted the
_prisma_migrations
table 3. we deleted the
migrations
folder 4. we then followed the instructions here on adding prisma to an existing project. a. ran
prisma pull db
b. ran
prisma migrate dev --name initial-migration --create-only
which resulted in yet another
Drift detected: Your database schema is not in sync with your migration history.
message. At this point we are kinda at a loss 😅 Does anyone know a good approach to take here?
t
Hi Tyler! It looks like you are hitting upgrade pains with constraint names. Have you read https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/upgrading-to-prisma-3/named-constraints/ ? There are ways out of this situation if you have multiple databases you can't reset with inconsistent constraint names, please ping me if you need more help 🙂 Btw deleting the migrations table and the migrations shouldn't be necessary at any point in this upgrade process.
t
Hi Tom! thanks for the reply! so at this point we are still using Prisma 2. We haven’t tried upgrading to 3 yet. The issues we’ve been running into have all been version 2 related.
However, I don’t think it’s Prisma’s fault. I believe we were using
migrate dev
when we should have been using
db push
which is what created the problems. At this point we are trying to figure out how to enable
migrate deploy
again without losing any production DB data.
t
Ok, tell me if you need assistance with anything. There's internal tools I could share for troubleshooting if the situation is hard to understand. In your case, I don't know if you are already using
migrate status
, but it could hlp.
t
Any assistance / recommendations would be awesome 🙂 We did try using
migrate status
but was still unable to resolve the issues.
@tom is there any way to schedule a quick chat / screen share?
t
Hi! Today is looking very busy, but I could do tomorrow at 1:30 pm CEST (I'm in Berlin), would that work?
t
Hey Tom, that would be great! My email for a cal invite is tyler@memberstack.com
Thank you so much!
t
awesome! the invitation is sent, see you soon
@Tyler Bell I'm in the zoom call
(just pinging in case we're out of sync on timezones)
I left the call because I think we missed each other because timezones, but I'm happy to reschedule to later today or next week (tomorrow I have PTO)
t
@tom sorry about that! I messed up the conversion yesterday 😔
f
hey @Tyler Bell - among others, this issue led to the creation of a new feature proposal
migrate diff
- please take a look if you have a moment and let us know if this would be useful: https://github.com/prisma/prisma/issues/10561