You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Drizzle中pgTable多对多关联遇TS弃用错误,主键生成失败

Drizzle多对多连接表TypeScript弃用错误修复

出现@deprecated — This overload is deprecated. Use the other method overload instead.错误,是因为Drizzle的primaryKey API已更新,原对象参数写法被废弃,改用直接传入列的重载形式即可解决。

修正后的代码:

export const usersToGroups = pgTable(
  'users_to_groups',
  {
    userId: integer('user_id')
      .notNull()
      .references(() => users.id),
    groupId: integer('group_id')
      .notNull()
      .references(() => groups.id),
  },
  (t) => ({
    pk: primaryKey(t.userId, t.groupId),
  }),
);

如果需要自定义主键名称,可添加第三个参数指定:

pk: primaryKey(t.userId, t.groupId, { name: 'users_to_groups_pk' }),

内容的提问来源于stack exchange,提问作者frost2709

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 15:57:04