© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
Gabriel

disambiguate foreign key relations

Help, I need to understand something:

export const team = mysqlTable(
  "Team",
  {
    id: varchar("id", { length: 191 }).notNull().primaryKey(),
    ownerId: varchar("ownerId", { length: 191 })
      .notNull()
      .references(() => user.id),
  },
  (table) => {
    return {
      ownerIdIdx: index("Team_ownerId_idx").on(table.ownerId),
    };
  },
);

export const user = mysqlTable("User", {
  id: varchar("id", { length: 191 }).notNull().primaryKey(),
  activeTeamId: varchar("activeTeamId", { length: 191 })
    .notNull()
    .references(() => team.id),
});
export const team = mysqlTable(
  "Team",
  {
    id: varchar("id", { length: 191 }).notNull().primaryKey(),
    ownerId: varchar("ownerId", { length: 191 })
      .notNull()
      .references(() => user.id),
  },
  (table) => {
    return {
      ownerIdIdx: index("Team_ownerId_idx").on(table.ownerId),
    };
  },
);

export const user = mysqlTable("User", {
  id: varchar("id", { length: 191 }).notNull().primaryKey(),
  activeTeamId: varchar("activeTeamId", { length: 191 })
    .notNull()
    .references(() => team.id),
});


This is giving me an error on team.id references and user.id references. I need to somehow disambiguate these relations I think but couldnt figure out how to do it. Drizzle has some info about disambiguation here:
https://orm.drizzle.team/docs/rqb#disambiguating-relations
But this is mainly for
relations()
relations()
functions where we dont specify actual fk constraints.
image.png
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

how to disambiguate query relations
Drizzle TeamDTDrizzle Team / help
3y ago
foreign key
Drizzle TeamDTDrizzle Team / help
3y ago
foreign key mismatch
Drizzle TeamDTDrizzle Team / help
2y ago
Inserting into tables with foreign key relationships
Drizzle TeamDTDrizzle Team / help
2y ago