prisma overwrite went wrong #1482

Closed
opened 2026-03-13 08:42:38 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @bilalnessMaster on GitHub (Jul 9, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

to reproduce this conflict you need to have a existign table on the prisma file
and id of user set be auto increment
and run the command
npx @better-auth/cli generate

Current vs. Expected behavior

I was having already tables on prisam file and I run the command :
npx @better-auth/cli generate
everything went great but the id of the user remaining auto_increment
and this make the relation between the session and user

Image

when try to migrate you face this problem its not a big deal but I just want to mention it

What version of Better Auth are you using?

1.2.12

Provide environment information

OS : ARCHLINUX
 BROWSER : BRAVE

Which area(s) are affected? (Select all that apply)

Documentation

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @bilalnessMaster on GitHub (Jul 9, 2025). ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce to reproduce this conflict you need to have a existign table on the prisma file and id of user set be auto increment and run the command npx @better-auth/cli generate ### Current vs. Expected behavior I was having already tables on prisam file and I run the command : npx @better-auth/cli generate everything went great but the id of the user remaining auto_increment and this make the relation between the session and user <img width="1920" height="1050" alt="Image" src="https://github.com/user-attachments/assets/8a0ec2e3-4468-40f2-8305-27938931de69" /> when try to migrate you face this problem its not a big deal but I just want to mention it ### What version of Better Auth are you using? 1.2.12 ### Provide environment information ```bash OS : ARCHLINUX BROWSER : BRAVE ``` ### Which area(s) are affected? (Select all that apply) Documentation ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
Author
Owner

@dosubot[bot] commented on GitHub (Jul 9, 2025):

Hi @bilalnessMaster! I'm Dosu and I’m helping the better-auth team.

This is a known limitation with the current better-auth CLI generator: when you run the generate command, it can overwrite your Prisma schema without fully preserving customizations like auto_increment or specific id field attributes. This sometimes leads to migration issues or mismatches between userId references and the user id type, especially if you already have tables defined or use number-based ids. The generator tries to detect existing models but doesn't always merge or respect all custom field attributes, so manual schema adjustments are often needed after generation to resolve these conflicts. There isn't robust merging logic or clear documentation for this yet, so the recommended workaround is to manually edit your schema after running the generator to ensure id fields and foreign key references match your requirements. Recent updates have improved schema generation, but users with existing custom Prisma schemas may still need to intervene manually for now example example.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 9, 2025): <!-- Greeting --> Hi @bilalnessMaster! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known limitation with the current better-auth CLI generator: when you run the generate command, it can overwrite your Prisma schema without fully preserving customizations like auto_increment or specific id field attributes. This sometimes leads to migration issues or mismatches between userId references and the user id type, especially if you already have tables defined or use number-based ids. The generator tries to detect existing models but doesn't always merge or respect all custom field attributes, so manual schema adjustments are often needed after generation to resolve these conflicts. There isn't robust merging logic or clear documentation for this yet, so the recommended workaround is to manually edit your schema after running the generator to ensure id fields and foreign key references match your requirements. Recent updates have improved schema generation, but users with existing custom Prisma schemas may still need to intervene manually for now [example](https://github.com/better-auth/better-auth/issues/3310) [example](https://github.com/better-auth/better-auth/pull/243). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/2ebcbdf2-0e0d-4faf-b03d-6e6a1b538ce7?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2ebcbdf2-0e0d-4faf-b03d-6e6a1b538ce7?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2ebcbdf2-0e0d-4faf-b03d-6e6a1b538ce7?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2ebcbdf2-0e0d-4faf-b03d-6e6a1b538ce7?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2ebcbdf2-0e0d-4faf-b03d-6e6a1b538ce7?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2ebcbdf2-0e0d-4faf-b03d-6e6a1b538ce7?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2ebcbdf2-0e0d-4faf-b03d-6e6a1b538ce7?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3320)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1482