Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

[Breaking Change] Foreign key for 1:n moved to another table. #202

Closed
sameoldmadness opened this issue Oct 29, 2019 · 1 comment
Closed
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.

Comments

@sameoldmadness
Copy link

Given a schema

model Merchant {
  id    String    @default(cuid()) @id
}

model Payload {
  id                   String           @default(cuid()) @id
  merchant .   Merchant?
}

When I update to preview15
And create a migration
I see a breaking change

ALTER TABLE "public"."Merchant" DROP COLUMN "Payload;

ALTER TABLE "public"."Payload" ADD COLUMN "merchant" text   REFERENCES "public"."Merchant"("id") ON DELETE SET NULL;

Expected behaviour: be able to perform this migration without a data loss.

@tomhoule
Copy link
Contributor

Thanks for reporting this :)

This migration was probably caused by a change we made recently in how prisma interprets "implicit self-relations" like the relation between Merchant and Payload in your schema. Relevant links: spec, PR.

And you are right, the current behaviour is leading to systematic data loss when doing that type of schema changes. We haven't had the time and resources to implement something better yet, but we are very much aware of that and are planning to work on it. Discussion is centralized here.

@pantharshit00 pantharshit00 added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. labels Oct 29, 2019
@janpio janpio closed this as completed May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

4 participants