FG
💻 Software🗄️ Databases

[BUG]: Unable to cast uuid to a field

Fresh5 days ago
Mar 14, 20260 views
Confidence Score54%
54%

Problem

What version of `drizzle-orm` are you using? 0.29.3 What version of `drizzle-kit` are you using? 0.20.14 Describe the Bug Hello, I'm new to drizzle but I have a error during migration, there is a problem with casting uuid, I expected uuid to be casted automatically in a field, I'm using PostgreSQL as my database of choice: [code block] schema.ts: [code block] Expected behavior _No response_ Environment & setup _No response_

Error Output

error during migration, there is a problem with casting uuid, I expected uuid to be casted automatically in a field, I'm using PostgreSQL as my database of choice:

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix UUID Casting Issue in Drizzle ORM Migration

Medium Risk

The issue arises because the Drizzle ORM version 0.29.3 does not automatically cast UUID types in PostgreSQL during migrations. This can lead to errors when attempting to insert or manipulate UUID fields, as the ORM may not recognize the correct data type.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update Drizzle ORM Configuration

    Ensure that your Drizzle ORM configuration explicitly defines the UUID type for the relevant fields in your schema. This will help the ORM understand how to handle UUIDs during migrations.

    typescript
    import { pgTable, uuid } from 'drizzle-orm';
    
    const users = pgTable('users', {
      id: uuid('id').primaryKey(),
      name: varchar('name'),
    });
  2. 2

    Check PostgreSQL UUID Extension

    Make sure that the UUID extension is enabled in your PostgreSQL database. You can do this by running the following SQL command in your database console.

    sql
    CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
  3. 3

    Run Migration Again

    After updating the schema and ensuring the UUID extension is enabled, attempt to run the migration again. This should resolve the casting issue.

    bash
    drizzle migrate
  4. 4

    Verify Migration Success

    Check the migration logs for any errors. If the migration completes successfully, verify that the UUID fields are correctly populated in the database.

    sql
    SELECT * FROM users;

Validation

Confirm that the migration completes without errors and that UUID fields in the database are correctly populated by querying the database and checking the data types.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

drizzleormtypescriptbug