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] }),
};
});
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server