Migration failed on existing database #266

Closed
opened 2026-03-13 07:40:13 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @MrKepzie on GitHub (Nov 23, 2024).

Running cli migrate fails on existing database because the fields are required but unset on existing accounts.
I understand that this is in beta, but shouldn't any added extra field be required=false ?
How am I supposed to go around this on my end ?

npx @better-auth/cli@latest migrate -y
(node:8687) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
ℹ  🔑 The migration will affect the following:                                                                                                                                            Better Auth
-> token, createdAt, updatedAt fields on session table.
-> accessTokenExpiresAt, refreshTokenExpiresAt, scope, createdAt, updatedAt fields on account table.
-> updatedAt fields on verification table.
⠋ migrating...node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

error: column "createdAt" of relation "account" contains null values

Originally created by @MrKepzie on GitHub (Nov 23, 2024). Running cli migrate fails on existing database because the fields are required but unset on existing accounts. I understand that this is in beta, but shouldn't any added extra field be `required=false` ? How am I supposed to go around this on my end ? ``` npx @better-auth/cli@latest migrate -y (node:8687) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created) ℹ 🔑 The migration will affect the following: Better Auth -> token, createdAt, updatedAt fields on session table. -> accessTokenExpiresAt, refreshTokenExpiresAt, scope, createdAt, updatedAt fields on account table. -> updatedAt fields on verification table. ⠋ migrating...node:internal/process/promises:289 triggerUncaughtException(err, true /* fromPromise */); ^ error: column "createdAt" of relation "account" contains null values ```
Author
Owner

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

If you are already using it in production, you should add the fields manually instead.

@Bekacru commented on GitHub (Nov 23, 2024): If you are already using it in production, you should add the fields manually instead.
Author
Owner

@MrKepzie commented on GitHub (Nov 23, 2024):

Could it be that the migrate tool prints the type of the fields that would be added aswell as their name ?

@MrKepzie commented on GitHub (Nov 23, 2024): Could it be that the migrate tool prints the type of the fields that would be added aswell as their name ?
Author
Owner

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

Yeah, it might not be a bad idea to show what fields need to be added, prior to migration, even if it fails. But for now, you can check the schema in the docs.https://www.better-auth.com/docs/concepts/database#core-schema

@Bekacru commented on GitHub (Nov 23, 2024): Yeah, it might not be a bad idea to show what fields need to be added, prior to migration, even if it fails. But for now, you can check the schema in the docs.https://www.better-auth.com/docs/concepts/database#core-schema
Author
Owner

@MrKepzie commented on GitHub (Nov 23, 2024):

ok thanks, as long as it's up to date it's fine!

@MrKepzie commented on GitHub (Nov 23, 2024): ok thanks, as long as it's up to date it's fine!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#266