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
相关产品推荐
相关产品推荐

