Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support databases without foreign keys #7293

Closed
janpio opened this issue May 27, 2021 · 1 comment · Fixed by prisma/prisma-engines#2221
Closed

Support databases without foreign keys #7293

janpio opened this issue May 27, 2021 · 1 comment · Fixed by prisma/prisma-engines#2221

Comments

@janpio
Copy link
Member

janpio commented May 27, 2021

Problem

There are databases that do not use foreign keys, for example PlanetScale that disallows them to be able to support Non Blocking Schema changes, MySQL MyISAM that just is to old and works well without, and many user databases where a choice was made not to use foreign keys as a concept for various reasons (Rails did not do a great job with them for quite some time and worked fine without, some people prefer to handle the referential integrity and actions manually in their app, for example to improve performance).

Right now Prisma does not work well with these database: Prisma Migrate will try to create foreign keys for relations by default, and Introspection will only introspect relations based on foreign keys. You can theoretically add relations to your Prisma schema without the backing foreign keys as long as the correct fields are present, but any Re-Introspection would remove these manually added relations from the schema file again.

Suggested solution

Introduce a configuration that allows Prisma to not user foreign keys. Prisma Migrate should not create them, Introspection should not drop relations if there are no foreign keys. Prisma Client should work the same as it does when using foreign keys.

Alternatives

  • Use another ORM instead of Prisma
  • Try to manually manage the relations in the schema file as described above

Additional context

Referential integrity and actions are closely related to this topic, but separate.

@pimeys
Copy link
Contributor

pimeys commented Sep 14, 2021

Migrations part done in here: prisma/prisma-engines#2212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants