[GH-ISSUE #689] Bug: CLI generates incorrect Prisma schema for MySQL #8381

Closed
opened 2026-04-13 03:27:22 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @JosipPardon on GitHub (Nov 28, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/689

First of all, thanks for this great library! We finally have complete solution for auth in next.js!

Bug 1.

CLI puts String type next to certain fields. Problem is that Prisma translates String to Varchar(191) in MySQL (see here). This is too small for some strings, like google auth values which are very big. I was constantly getting "The provided value for the column is too long for the column's type" error.
Solution is to put @db.Text next to these fields, so that they can store strings longer than 191 characters:

value      String    @db.Text
...
accessToken           String?   @db.Text
refreshToken          String?   @db.Text
idToken               String?   @db.Text

Maybe there are some other fields which I forgot to mention.

Bug 2.

this was missing from User:

sessions      Session[]
accounts      Account[]

Improvement 1.

Why there is no cascade delete in generated schema? So that when user gets deleted, all accounts and sessions connected to him are also deleted automatically.

Improvement 2.

Currently, we have to set database provider for Prisma in two places: our original prisma.schema and in auth.ts. This means we have two manually sync them, there is no one single source of truth, which creates room for potential error. It would be better to define provider just in prisma.schema.

Recommendation

I think that all this CLI schema generation is not necessary, it just complicates things and increases package size. It would be easier and better to just copy table/property definitions from docs into our original schema.prisma. This is how next-auth and lucia-auth work, and it is pretty good.

Originally created by @JosipPardon on GitHub (Nov 28, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/689 First of all, thanks for this great library! We finally have complete solution for auth in next.js! ## Bug 1. CLI puts `String` type next to certain fields. Problem is that Prisma translates `String` to `Varchar(191)` in MySQL (see [here](https://www.prisma.io/docs/orm/reference/prisma-schema-reference#default-type-mappings)). This is too small for some strings, like google auth values which are very big. I was constantly getting "_The provided value for the column is too long for the column's type_" error. Solution is to put `@db.Text` next to these fields, so that they can store strings longer than 191 characters: ``` value String @db.Text ... accessToken String? @db.Text refreshToken String? @db.Text idToken String? @db.Text ``` Maybe there are some other fields which I forgot to mention. ## Bug 2. this was missing from `User`: ``` sessions Session[] accounts Account[] ``` ## Improvement 1. Why there is no cascade delete in generated schema? So that when user gets deleted, all accounts and sessions connected to him are also deleted automatically. ## Improvement 2. Currently, we have to set database provider for Prisma in two places: our original _prisma.schema_ and in _auth.ts_. This means we have two manually sync them, there is no one single source of truth, which creates room for potential error. It would be better to define provider just in _prisma.schema_. ## Recommendation I think that all this CLI schema generation is not necessary, it just complicates things and increases package size. It would be easier and better to just copy table/property definitions from docs into our original _schema.prisma_. This is how next-auth and lucia-auth work, and it is pretty good.
GiteaMirror added the lockedbug labels 2026-04-13 03:27:22 -05:00
Author
Owner

@Bekacru commented on GitHub (Nov 29, 2024):

Thanks for reporting the issue! The mysql issue will be fixed :)

Regarding cascade delete, the schema is meant to be a starting point—you can add it yourself. That said, it might not be a bad idea to include it on our side.

As for #2, if there’s an easier way to determine the database being used from the Prisma client, feel free to open a PR. I couldn’t find one, which is why we require explicit definitions. It’s not a huge amount of work since it rarely changes, but it would, of course, be nice to avoid requiring it.

Regarding the recommendation, we have a plugin system where each plugin can add its own schema, whether it’s a new table, field, or something else. Providing a copyable schema for every adapter we support would be unnecessary work and doesn’t simplify anything for us for the user.

<!-- gh-comment-id:2507300617 --> @Bekacru commented on GitHub (Nov 29, 2024): Thanks for reporting the issue! The mysql issue will be fixed :) Regarding cascade delete, the schema is meant to be a starting point—you can add it yourself. That said, it might not be a bad idea to include it on our side. As for #2, if there’s an easier way to determine the database being used from the Prisma client, feel free to open a PR. I couldn’t find one, which is why we require explicit definitions. It’s not a huge amount of work since it rarely changes, but it would, of course, be nice to avoid requiring it. Regarding the recommendation, we have a plugin system where each plugin can add its own schema, whether it’s a new table, field, or something else. Providing a copyable schema for every adapter we support would be unnecessary work and doesn’t simplify anything for us for the user.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8381