question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`prisma db push` generating identifier names longer than 64 characters

See original GitHub issue

Bug description

I have relations between complex objects that generates long identifier names. While executing prisma db push Prisma appends ‘_ibfk_1’ even if it will have more than 64 characters after appending. My use case is to be used by Jest for pushing the schema into test database.

It rejects promise:

Promise {
        <rejected> Error: Command failed: /Users/../../../node_modules/.bin/prisma db push --preview-feature
        Error: Database error: Error querying the database: Server error: `ERROR 42000 (1059): Identifier name 'foundation_variable_set_foundation_configuration_values_aud_ibfk_1' is too long'
           0: sql_migration_connector::sql_database_step_applier::apply_step
                   with index=0
                     at migration-engine/connectors/sql-migration-connector/src/sql_database_step_applier.rs:14
           1: migration_core::api::SchemaPush
                     at migration-engine/core/src/api.rs:166

How to reproduce

  1. Have a Prisma schema in which there are table names with length larger than 57 characters (64 - 7) as ‘_ibfk_1’ has 7 characters.
  2. run prisma db push --preview-feature
  3. Expect an error to be thrown

Expected behavior

Generate an alternative name which is shorter than 64 characters, or Let the user choose custom name for the identifier

In my case I can’t really change the MySQL schema and I need to work with what I have. I know these names are unnecessary and repetitive but that’s what Prisma generates.

Prisma information

The schema is pretty big so I include the part of it:

model foundation_variable_set_foundation_configuration_values_aud {
  REV                Int
  CompanyVariable_id Int
  valueList_id       Int
  REVTYPE            Int?
  DeviceVariable_id  Int
  GroupVariable_id   Int
  revinfo            revinfo @relation(fields: [REV], references: [REV])

  @@id([REV, GroupVariable_id, valueList_id])
}

Environment & setup

  • OS: MacOS
  • Database: MySQL
  • Node.js version: 12.16.1
  • Prisma version: 12.15.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
do4grcommented, Aug 11, 2021

A fix for this issue is now available via the namedConstraints preview flag since 2.29. It implements both solutions mentioned above, a default name generation that respects db name length limits and the option for user-specified names.

See https://www.prisma.io/docs/guides/upgrade-guides/upgrading-to-use-preview-features/enabling-named-constraints

0reactions
tomhoulecommented, Jun 25, 2021

This is currently being worked on, expect a preview feature to make it into a release soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma schema API (Reference)
When running a Prisma CLI command that needs the database connection URL (e.g. prisma generate ), you need to make sure that the...
Read more >
Error message reference - Prisma
Prisma Client throws a PrismaClientUnknownRequestError exception if the query engine returns an error related to a request that does not have an error...
Read more >
Names in the underlying database - Prisma
Mapping names in the Prisma schema allows you to influence the naming in your Client API without having to change the underlying database...
Read more >
Upgrade to Prisma 4
Prisma 4 introduces a number of breaking changes when you upgrade from an earlier Prisma version. This guide explains how this upgrade might...
Read more >
Schema prototyping with db push - Prisma
How to use db push to prototype a new feature or an entirely new schema. ... Although db push and Prisma Migrate both...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found