© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
1 reply
Penners

SQLite composite primary key error.

I'm trying to add a composite primary key for the following table but I'm getting a type error. I've referenced the docs and this looks to be the correct syntax so I'm just a little confused. https://orm.drizzle.team/docs/indexes-constraints#composite-primary-key

    "drizzle-orm": "^0.28.6",
    "drizzle-orm": "^0.28.6",


Error:
Argument of type '{ columns: (SQLiteColumn<{ name: "event_id"; tableName: "latest_odds"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, object> | SQLiteColumn<...> | SQLiteColumn<...> | SQLiteColumn<...>)[]; }' is not assignable to parameter of type 'AnySQLiteColumn<{ tableName: string; }>'.
  Object literal may only specify known properties, and 'columns' does not exist in type 'SQLiteColumn<Required<{ name: string; dataType: ColumnDataType; columnType: string; data: unknown; driverParam: unknown; notNull: boolean; hasDefault: boolean; enumValues: string[] | undefined; tableName: string; }>, object>'
Argument of type '{ columns: (SQLiteColumn<{ name: "event_id"; tableName: "latest_odds"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, object> | SQLiteColumn<...> | SQLiteColumn<...> | SQLiteColumn<...>)[]; }' is not assignable to parameter of type 'AnySQLiteColumn<{ tableName: string; }>'.
  Object literal may only specify known properties, and 'columns' does not exist in type 'SQLiteColumn<Required<{ name: string; dataType: ColumnDataType; columnType: string; data: unknown; driverParam: unknown; notNull: boolean; hasDefault: boolean; enumValues: string[] | undefined; tableName: string; }>, object>'


Schema Def:
import {
  index,
  integer,
  primaryKey,
  real,
  sqliteTable,
  text,
} from "drizzle-orm/sqlite-core";

export const LatestOdds = sqliteTable(
  "latest_odds",
  {
    eventId: text("event_id").notNull(),
    eventName: text("event_name"),
    marketId: text("market_id").notNull(),
    marketName: text("market_name"),
    outcomeId: text("outcome_id").notNull(),
    outcome: text("outcome").notNull(),
    oddsDecimal: real("odds_decimal"),
    oddsFractional: text("odds_fractional"),
    timestamp: integer("timestamp", { mode: "timestamp_ms" })
      .default(sql`CURRENT_TIMESTAMP`)
      .notNull(),
    bookmaker: text("bookmaker").notNull(),
  },
  (table) => {
    return {
      pk: primaryKey({
        columns: [
          table.eventId,
          table.marketId,
          table.outcomeId,
          table.bookmaker,
        ],
      }),
    };
  }
);
import {
  index,
  integer,
  primaryKey,
  real,
  sqliteTable,
  text,
} from "drizzle-orm/sqlite-core";

export const LatestOdds = sqliteTable(
  "latest_odds",
  {
    eventId: text("event_id").notNull(),
    eventName: text("event_name"),
    marketId: text("market_id").notNull(),
    marketName: text("market_name"),
    outcomeId: text("outcome_id").notNull(),
    outcome: text("outcome").notNull(),
    oddsDecimal: real("odds_decimal"),
    oddsFractional: text("odds_fractional"),
    timestamp: integer("timestamp", { mode: "timestamp_ms" })
      .default(sql`CURRENT_TIMESTAMP`)
      .notNull(),
    bookmaker: text("bookmaker").notNull(),
  },
  (table) => {
    return {
      pk: primaryKey({
        columns: [
          table.eventId,
          table.marketId,
          table.outcomeId,
          table.bookmaker,
        ],
      }),
    };
  }
);
Indexes & Constraints - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
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

Composite Primary Key?
Drizzle TeamDTDrizzle Team / help
16mo ago
reference composite primary key
Drizzle TeamDTDrizzle Team / help
3y ago
Composite primary key, multiple primary keys
Drizzle TeamDTDrizzle Team / help
2y ago
Compostie primary key of a composite primary key
Drizzle TeamDTDrizzle Team / help
2y ago