Skip to content

Inconsistent casing in Migrations #12053

Open

Description

@hrueger

Bug description

When creating a migation on Windows (with MariaDB), the casing of the table names is not consistent. Sometimes it uses lowercase, sometimes pascalcase in the warnings when renaming a column.

This is linked to #6972 as the generated migration will fail on linux-based OSes.

You can find all info and a reproduction in my repository.

How to reproduce

See my repo for full instructions and a reproduction.
Basically, you need to:

  1. use windows
  2. rename a column in the prisma schema
  3. generate a migration using npx prisma migrate dev

Expected behavior

All table names are in PascalCase because that does work fine on Windows and doesn't crash on linux (like with the lowercase names).

Prisma information

https://github.com/hrueger/prisma-inconsistent-casing-issue

Environment & setup

  • OS: Windows 10
  • Database: MariaDB
  • Node.js version: v17.4.0

Prisma Version

prisma                  : 3.10.0
@prisma/client          : Not found
Current platform        : windows
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio                  : 0.458.0

Activity

  1. added
    kind/bug
    on Feb 26, 2022
  2. changed the title [-]Inconsistent casing in [/-] [+]Inconsistent casing in Migrations[/+] on Feb 26, 2022
  3. added
    bug/1-unconfirmed
    on Feb 26, 2022
  4. added
    tech/engines
    on Mar 24, 2022
  5. RobertSandiford commented on Apr 10, 2022

    @RobertSandiford
    Contributor

    Experiencing the same issue.

  6. RobertSandiford commented on Apr 11, 2022

    @RobertSandiford
    Contributor

    TLDR: Set "lower_case_table_names" to 2 on windows in my.cnf/my.ini under [mysqld]. Prisma can avoid issues by always taking table name casing from schema not the database.


    Windows has a case-insensitive file system. Correspondingly MySQL / MariaDB on windows has a server setting of lower_case_file_system = ON
    Read "lower case file system" as "case insensitive file system". This value can't be changed.

    On windows "lower_case_table_names" defaults to 1, which means that table names are converted to lower case.

    I believe the issue in prisma occurs because during alterations to tables, the table name is read from the database, not the schema, and the lower case form is used in migrations, while the schema form is using in create statements (there may be some more nuances as to exactly where each approach is used).

    The problem can be solved easily by setting "lower_case_table_names" to 2 which retains upper case characters in table names, and so too in prisma migrations. Actual table lookups are still case-insensitive (table names are converted to lowercase during comparisons, so would have a small perfomance hit). This can be set in a config file, e.g. my.cnf or my.ini, under [mysqld]

    Prisma can check for lower_case_file_system = ON and lower_case_table_names = 1 to identify the offending setup.
    SHOW VARIABLES WHERE Variable_name = 'lower_case_file_system'

    Prisma can either warn about the issue, or alternatively resolve the issue entirely by looking up the schema for the intended case for ALTER statements instead of taking the casing from the database. Casing between migrations and the actual database would differ on windows, but I see no problem with that given comparisons will be case-insensitive. This would not be an ideal solution if a windows server were to be used in production, but is fine for development.

    Prisma should not lowercase table names in this scenario because it would break interop between developers on different OSs. However, lowercasing all table names throughout would be an alternative solution, that would be preferable if windows was to be used in production.

  7. bhuynhdev commented on Mar 12, 2023

    @bhuynhdev

    Experiencing this same problem. As seen here in this migration file warning, when I try to rename column and recreate index. The DROP INDEX (and the first warning sentence) uses note whereas CREATE INDEX uses Note

    - You are about to drop the column `userId` on the `note` table. All the data in the column will be lost.
    - Added the required column `authorId` to the `Note` table without a default value. This is not possible if the table is not empty.
    
    DROP INDEX `Note_userId_idx` ON `note`;
    
    -- DropIndex
    DROP INDEX `Note_userId_idx` ON `Note`;
    
    -- AlterTable
    ALTER TABLE `note` RENAME COLUMN `userId` TO `authorId`;
    
    -- CreateIndex
    CREATE INDEX `Note_authorId_idx` ON `Note`(`authorId`);
    
  8. RobertSandiford commented on Mar 12, 2023

    @RobertSandiford
    Contributor

    Experiencing this same problem.

    Solution you can use above for MySQL/MariaDB. I suppose you will also need to reset your DB afterwards

  9. erjenkins29 commented on Sep 26, 2023

    @erjenkins29

    I also ran into this today -- prisma 5.3.1, mysql, and developing on windows. I'm not seeing whether this was resolved or attempted to be resolved?

  10. Aloysius999 commented on Aug 15, 2024

    @Aloysius999

    This issue appears not to have been fixed.
    I encountered this problem today on Ubuntu using Prisma 5.18.0.
    Changing the value of lower_case_table_names is not easy on a DB that has already been deployed and used - it is a setting that is configured during initial deployment.

  11. ViniciusLeviVL commented on Aug 15, 2024

    @ViniciusLeviVL

    Same issue here.

  12. hkiame commented on Sep 13, 2024

    @hkiame

    facing the same issue

  13. SamuelSmeys commented on Sep 29, 2024

    @SamuelSmeys

    Facing the same issue on my end as well. I'm on MacOs Sonoma with Prisma 5.20

  14. alfanzain commented on Jan 9, 2025

    @alfanzain

    Facing the same issue on Windows 10 with Prisma 5.20

  15. abdullahsaif99 commented on Feb 14, 2025

    @abdullahsaif99

    I am facing same issue. Let's say table name is User. In migration it changes to user. Moreover, it appears same for each one.

  16. R1NEJ0 commented on Apr 10, 2025

    @R1NEJ0

    Same issue on windows 11 with prisma 6.5

  17. bahaa-homecuz commented on Dec 16, 2025

    @bahaa-homecuz

    i have the same issue

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedkind/bugtech/enginestopic: mariadbtopic: windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions