© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
81 replies
David L. Bowman

Changing `id` type from serial to uuid, causing error.

I'm sorry, I'm new to Drizzle, but I've read through the documentation and discord and cannot find a solution to my problem.

I'm using Next.js 14, Postgresql through Vercel.

When I first started, I built a test
UsersTable
UsersTable
but now I want to change the
id
id
from a
serial
serial
to a
uuid
uuid
. Everytime I try to
generate:pg
generate:pg
it works, but
push:pg
push:pg
fails, giving the following error:

error: column "id" cannot be cast automatically to type uuid
  code: '42804',
  hint: 'You might need to specify "USING id::uuid".',
error: column "id" cannot be cast automatically to type uuid
  code: '42804',
  hint: 'You might need to specify "USING id::uuid".',


Could you please tell me how I'm supposed to update my table?

import { pgTable, uuid, varchar, timestamp } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"

export const UsersTable = pgTable("users", {
    id: uuid("id").defaultRandom(),
    firstName: varchar("first_name", { length: 50 }).notNull(),
    lastName: varchar("last_name", { length: 50 }).notNull(),
    email: varchar("email", { length: 100 }).notNull().unique(),
    password: varchar("password", { length: 100 }).notNull(),
    createdAt: timestamp("created_at").defaultNow().notNull(),
    updatedAt: timestamp("updated_at").defaultNow().notNull()
})
import { pgTable, uuid, varchar, timestamp } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"

export const UsersTable = pgTable("users", {
    id: uuid("id").defaultRandom(),
    firstName: varchar("first_name", { length: 50 }).notNull(),
    lastName: varchar("last_name", { length: 50 }).notNull(),
    email: varchar("email", { length: 100 }).notNull().unique(),
    password: varchar("password", { length: 100 }).notNull(),
    createdAt: timestamp("created_at").defaultNow().notNull(),
    updatedAt: timestamp("updated_at").defaultNow().notNull()
})
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

how to convert serial to uuid type
Drizzle TeamDTDrizzle Team / help
3y ago
error: column "id" cannot be cast automatically to type uuid
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle schema vs SQL when migrating serial id to uuid?
Drizzle TeamDTDrizzle Team / help
2y ago
`id` type is `undefined` when using `serial("id").primaryKey()`
Drizzle TeamDTDrizzle Team / help
2y ago