better-auth-kit icon indicating copy to clipboard operation
better-auth-kit copied to clipboard

Migration Failure: Adding legalConsent boolean field to existing user table fails due to null values

Open allandelmare opened this issue 1 year ago • 0 comments

When enabling a legalConsent option (e.g., requirePrivacyPolicy: true) which adds a new boolean column (e.g., privacyPolicyAccepted) to the user table, running npx @better-auth/cli migrate fails if the user table already contains existing rows.

error: column "privacyPolicyAccepted" of relation "user" contains null values at /path/to/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:... ... (rest of stack trace) ...

Steps to Reproduce:

  1. Have an existing Better Auth setup with users in the user table.
  2. Enable a new legalConsent option in auth.ts (e.g., legalConsent({ requirePrivacyPolicy: true })).
  3. Run npx @better-auth/cli migrate.

allandelmare avatar May 09 '25 12:05 allandelmare