Confused about onConflictDoUpdate when having a constraint

I have a table that looks like
export const weeklyFinalRankings = pgTable(
  'weekly_final_rankings',
  {
    id: serial('id').primaryKey(),
    division: varchar('division', { length: 10 }).notNull(),
    week: integer('week').notNull(),
    year: integer('year').notNull(),
    rankings: jsonb('rankings').notNull(),
  },
  (table) => ({
    isUniqueVote: unique().on(table.year, table.week),
  }),
)


and after going through some docs, I was doing an insert like so
await db
  .insert(weeklyFinalRankings)
  .values({
    division,
    year: 2024,
    week: 0,
    rankings: rankedTeams,
  })
  .onConflictDoUpdate({
    target: weeklyFinalRankings.week,
    set: { rankings: rankedTeams },
  })


However, I get PostgresError: there is no unique or exclusion constraint matching the ON CONFLICT specification

What am I doing incorrect here?
Was this page helpful?