© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
Backrooms Player

column "player_id" cannot be cast automatically to type uuid in drizzle ORM

I am trying to create a schema for my application, for context my application is a sports match manager, so an admin can create many matches, users can register for those matches and at the day of the match the system will automatically assign random teams to every registered user, users can then click on each match and find out the teams, and who plays for which team.


import { integer, pgTable, primaryKey, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core";

export const players = pgTable('players', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
  name: text('name').notNull(),
  playerImg: varchar('player_img', { length: 256 }),
  goals: integer('goals').notNull().default(0),
  assists: integer('assists').notNull().default(0),
});

export const matches = pgTable('matches', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
  location: text('location').notNull(),
  matchDate: timestamp('match_date', { withTimezone: true }).notNull(),
  team1Id: integer('team1_id').references(() => teams.id).notNull(),
  team2Id: integer('team2_id').references(() => teams.id).notNull(),
});

export const teams = pgTable('teams', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
});

export const playerRegistrations = pgTable('player_registrations', {
  playerId: uuid('player_id').notNull().references(() => players.id),
  teamId: uuid('team_id').notNull().references(() => teams.id),
  matchId: uuid('match_id').notNull().references(() => matches.id),
}, (table) => {
  return {
    pk: primaryKey({ columns: [table.playerId, table.teamId, table.matchId] }),
  };
});
import { integer, pgTable, primaryKey, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core";

export const players = pgTable('players', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
  name: text('name').notNull(),
  playerImg: varchar('player_img', { length: 256 }),
  goals: integer('goals').notNull().default(0),
  assists: integer('assists').notNull().default(0),
});

export const matches = pgTable('matches', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
  location: text('location').notNull(),
  matchDate: timestamp('match_date', { withTimezone: true }).notNull(),
  team1Id: integer('team1_id').references(() => teams.id).notNull(),
  team2Id: integer('team2_id').references(() => teams.id).notNull(),
});

export const teams = pgTable('teams', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
});

export const playerRegistrations = pgTable('player_registrations', {
  playerId: uuid('player_id').notNull().references(() => players.id),
  teamId: uuid('team_id').notNull().references(() => teams.id),
  matchId: uuid('match_id').notNull().references(() => matches.id),
}, (table) => {
  return {
    pk: primaryKey({ columns: [table.playerId, table.teamId, table.matchId] }),
  };
});
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

error: column "id" cannot be cast automatically to type uuid
Drizzle TeamDTDrizzle Team / help
3y ago
Column _ cannot be cast automatically to type integer
Drizzle TeamDTDrizzle Team / help
3y ago
column "summary" cannot be cast automatically to type jsonb
Drizzle TeamDTDrizzle Team / help
3y ago
Cannot be cast automatically
Drizzle TeamDTDrizzle Team / help
11mo ago