© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
11 replies
piscopancer

2 tables cannot reference each others columns?

I have the following tables declaration:
export const questionsTable = sqliteTable('questions', {
  // bla bla
  acceptedAnswerId: text('accepted_answer_id').references(() => answersTable.id, {onDelete: 'cascade'}), // ERROR HERE
})

export const answersTable = sqliteTable('answers', {
  // bla bla
  questionId: text('question_id')
    .notNull()
    .references(() => questionsTable.id, { onDelete: 'cascade' }), // THIS REFERENCE DOES NOT LET ME CREATE A REFERENCE TO answersTable.id IN questionsTable.acceptedAnswerId, LOOK ABOVE
})
export const questionsTable = sqliteTable('questions', {
  // bla bla
  acceptedAnswerId: text('accepted_answer_id').references(() => answersTable.id, {onDelete: 'cascade'}), // ERROR HERE
})

export const answersTable = sqliteTable('answers', {
  // bla bla
  questionId: text('question_id')
    .notNull()
    .references(() => questionsTable.id, { onDelete: 'cascade' }), // THIS REFERENCE DOES NOT LET ME CREATE A REFERENCE TO answersTable.id IN questionsTable.acceptedAnswerId, LOOK ABOVE
})

As you can see, for some reason I CANNOT reference one table's column from the other table, while this table's column is already referenced by the other table. Can you explain why so and what should I do?
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

generated columns reference another table
Drizzle TeamDTDrizzle Team / help
2y ago
Cannot join tables where the columns name are the same.
Drizzle TeamDTDrizzle Team / help
3y ago
Adding Columns or Merging Tables
Drizzle TeamDTDrizzle Team / help
3y ago
Two tables that references each other
Drizzle TeamDTDrizzle Team / help
2y ago