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.

Inconsistent table names in migrations

See original GitHub issue

Bug description

The capitalization for generated table names appears to be inconsistent. When creating new tables, the migrations contain the capitalized and correct version of the table names, however altering the model causes an alter migration to be created with a fully lowercase version of the table name. This causes issues where migrate fails because it cannot find the right table.

Creation migration: image

Alter migration: image

This causes my production setup to break with The underlying table for model 'report' does not exist.

How to reproduce

  1. Create a migration adding a new table
  2. Create a migration that alters the previously created table
  3. The generated alter query will use a lowercase version of the table name

Expected behavior

The migration files should contain the actual model names, which in my case are capitalized

Environment & setup

  • OS: Windows 10
  • Database: MariaDB
  • Node.js version: v12.18.4
  • Prisma version:
prisma               : 2.22.0
@prisma/client       : 2.22.0
Current platform     : windows
Query Engine         : query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 60cc71d884972ab4e897f0277c4b84383dddaf6c (at  node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 60cc71d884972ab4e897f0277c4b84383dddaf6c
Studio               : 0.379.0
Preview Features     : orderByRelation

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
macjuulcommented, May 6, 2021

I’ve managed to reproduce it with a simple example

Initial schema:

generator client {
    provider        = "prisma-client-js"
    previewFeatures = ["orderByRelation"]
}

datasource db {
    provider = "mysql"
    url      = env("DATABASE_URL")
}

model User {
    id   Int    @id @default(autoincrement())
    name String
}

Which generates the following migration:

-- CreateTable
CREATE TABLE `User` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

If I now add a new status field to my User model like so:

model User {
    id     Int    @id @default(autoincrement())
    name   String
    status String @default("active")
}

The following migration will be generated, this time with a lowercase table name:

-- AlterTable
ALTER TABLE `user` ADD COLUMN `status` VARCHAR(191) NOT NULL DEFAULT 'active';
0reactions
pantharshit00commented, May 6, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent casing in Migrations #12053 - prisma ... - GitHub
I believe the issue in prisma occurs because during alterations to tables, the table name is read from the database, not the schema,...
Read more >
Flutter Drift library inconsistency found while naming table and ...
I want my table names to be specific as I am migrating from Native Android Room database to Flutter using Drift library for...
Read more >
How to fix inconsistency between the snapshot and migrations?
Hello,. There is an inconsistency when editing relationships between entities. I also deleted a migration, How can I fix this inconsistency?
Read more >
Table names inconsistent across platforms - concrete5
I checked MySQL on XAMPP and found that all the table names are lower case. Meaning the backup did work in XAMPP but...
Read more >
Rename table without downtime - GitLab Docs
After running the migration locally, check if there are inconsistently named indexes ( db/structure.sql ). Those can be renamed manually in a separate...
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