Primary key is not applied

Drizzle doesn't generate a primary key statement in the migration. Here is the schema:
export const usersTable = pgTable(
"users",
{
slackUserId: text().notNull(),
slackTeamId: text().notNull(),
tokenSet: jsonb().notNull(),
createdAt: timestamp().notNull().defaultNow(),
},
(t) => [{ pk: primaryKey({ columns: [t.slackUserId, t.slackTeamId] }) }],
);
export const usersTable = pgTable(
"users",
{
slackUserId: text().notNull(),
slackTeamId: text().notNull(),
tokenSet: jsonb().notNull(),
createdAt: timestamp().notNull().defaultNow(),
},
(t) => [{ pk: primaryKey({ columns: [t.slackUserId, t.slackTeamId] }) }],
);
drizzle-kit: "^0.30.0" drizzle-orm: "^0.38.0"
3 Replies
Mario564
Mario5642w ago
@Eduard Dyckman There's a slight issue with the syntax. Try doing this instead:
export const usersTable = pgTable(
"users",
{
slackUserId: text().notNull(),
slackTeamId: text().notNull(),
tokenSet: jsonb().notNull(),
createdAt: timestamp().notNull().defaultNow(),
},
(t) => [primaryKey({ columns: [t.slackUserId, t.slackTeamId] })], // this line changed
);
export const usersTable = pgTable(
"users",
{
slackUserId: text().notNull(),
slackTeamId: text().notNull(),
tokenSet: jsonb().notNull(),
createdAt: timestamp().notNull().defaultNow(),
},
(t) => [primaryKey({ columns: [t.slackUserId, t.slackTeamId] })], // this line changed
);
Eduard Dyckman
Eduard DyckmanOP2w ago
Nice, thanks! That helped! I think I was just following the official guide though
Mario564
Mario5642w ago
The docs haven't been updated to reflect the new syntax, so there's quite a bit of confusion surrounding this
Want results from more Discord servers?
Add your server