NextAuth to Better-Auth migration issue with Drizzle + Postgres (emailVerified cast error) #2249

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

Originally created by @moshefortgang on GitHub (Nov 2, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Followed the steps in the guide:
https://www.better-auth.com/docs/guides/next-auth-migration-guide

Migration fails on the emailVerified column in the user table.

The change applied according to the guide:

- emailVerified: timestamp("emailVerified", { mode: "date" }),
+ emailVerified: boolean("emailVerified").default(false).notNull(),

Then ran:

npx drizzle-kit generate
npx drizzle-kit migrate

Current vs. Expected behavior

Current behavior:
The following error occurs:
[⣷] applying migrations...error: column "emailVerified" cannot be cast automatically to type boolean
Postgres cannot automatically cast from timestamp to boolean.

Expected behavior:
Migration should succeed without errors, or the guide should indicate the need to rename the column or handle the cast explicitly.

What version of Better Auth are you using?

1.3.32

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#85~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 19 16:18:59 UTC 2",
    "release": "6.8.0-85-generic",
    "cpuCount": 12,
    "cpuModel": "12th Gen Intel(R) Core(TM) i7-1255U",
    "totalMemory": "15.31 GB",
    "freeMemory": "3.85 GB"
  },
  "node": {
    "version": "v22.17.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "latest"
    },
    {
      "name": "react",
      "version": "^19.2.0"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "postgres",
      "version": "^3.4.7"
    },
    {
      "name": "drizzle",
      "version": "^0.36.4"
    },
    {
      "name": "@vercel/postgres",
      "version": "^0.10.0"
    }
  ],
  "betterAuth": {
    "version": "^1.3.32",
    "config": {
      "emailAndPassword": {
        "enabled": true
      },
      "socialProviders": {
        "google": {}
      }
    }
  }
}

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

Other

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db";

export const auth = betterAuth({
    database: drizzleAdapter(db, {
    provider: "pg",
    usePlural: true
  }),
  emailAndPassword: { enabled: true },
  socialProviders: {
    google: {
      clientId: process.env.AUTH_GOOGLE_ID!,
      clientSecret: process.env.AUTH_GOOGLE_SECRET!,
    },
  },
});

Additional context

No response

Originally created by @moshefortgang on GitHub (Nov 2, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Followed the steps in the guide: https://www.better-auth.com/docs/guides/next-auth-migration-guide Migration fails on the emailVerified column in the user table. The change applied according to the guide: ``` - emailVerified: timestamp("emailVerified", { mode: "date" }), + emailVerified: boolean("emailVerified").default(false).notNull(), ``` Then ran: ``` npx drizzle-kit generate npx drizzle-kit migrate ``` ### Current vs. Expected behavior **Current behavior:** The following error occurs: `[⣷] applying migrations...error: column "emailVerified" cannot be cast automatically to type boolean ` Postgres cannot automatically cast from timestamp to boolean. **Expected behavior:** Migration should succeed without errors, or the guide should indicate the need to rename the column or handle the cast explicitly. ### What version of Better Auth are you using? 1.3.32 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#85~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 19 16:18:59 UTC 2", "release": "6.8.0-85-generic", "cpuCount": 12, "cpuModel": "12th Gen Intel(R) Core(TM) i7-1255U", "totalMemory": "15.31 GB", "freeMemory": "3.85 GB" }, "node": { "version": "v22.17.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "next", "version": "latest" }, { "name": "react", "version": "^19.2.0" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "postgres", "version": "^3.4.7" }, { "name": "drizzle", "version": "^0.36.4" }, { "name": "@vercel/postgres", "version": "^0.10.0" } ], "betterAuth": { "version": "^1.3.32", "config": { "emailAndPassword": { "enabled": true }, "socialProviders": { "google": {} } } } } ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@/db"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", usePlural: true }), emailAndPassword: { enabled: true }, socialProviders: { google: { clientId: process.env.AUTH_GOOGLE_ID!, clientSecret: process.env.AUTH_GOOGLE_SECRET!, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the integration label 2026-03-13 09:38:27 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 2, 2025):

This error occurs because PostgreSQL cannot automatically convert a timestamp value to a boolean. The recommended next step is to modify your migration so that the change is explicit. For example, you can update your migration script to use a USING clause that converts any non‑null timestamp into true (or false, depending on your desired logic). One common approach is:

  ALTER TABLE "user"
  ALTER COLUMN "emailVerified" TYPE boolean
  USING ("emailVerified" IS NOT NULL);

Alternatively, if preserving the old data isn’t necessary, you can rename or drop the old "emailVerified" column and add a new boolean column with a default of false. Be sure to adjust any related application logic accordingly.

This explicit cast or two‑step migration is needed because the guide’s change from timestamp to boolean doesn’t include instructions for handling the conversion automatically. If you choose to use the USING clause, review your current data in that column to determine the correct conversion logic.

Let me know if you need further clarification on these steps [1].

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 2, 2025): This error occurs because PostgreSQL cannot automatically convert a timestamp value to a boolean. The recommended next step is to modify your migration so that the change is explicit. For example, you can update your migration script to use a USING clause that converts any non‑null timestamp into true (or false, depending on your desired logic). One common approach is:   ALTER TABLE "user"   ALTER COLUMN "emailVerified" TYPE boolean   USING ("emailVerified" IS NOT NULL); Alternatively, if preserving the old data isn’t necessary, you can rename or drop the old "emailVerified" column and add a new boolean column with a default of false. Be sure to adjust any related application logic accordingly. This explicit cast or two‑step migration is needed because the guide’s change from timestamp to boolean doesn’t include instructions for handling the conversion automatically. If you choose to use the USING clause, review your current data in that column to determine the correct conversion logic. Let me know if you need further clarification on these steps [[1]](https://github.com/better-auth/better-auth/issues/1027). <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2249