Error: There is not enough information to infer relation - one to many

Getting this error when attempting to query or load up studio. Here is my schema
import { relations } from 'drizzle-orm';
import { serial, text, timestamp, pgTable, date, integer } from 'drizzle-orm/pg-core';

export const habits = pgTable('habits', {
id: serial('id').primaryKey(),
name: text('name'),
days_per_month: integer('days_per_month'),
created_at: timestamp('created_at'),
updated_at: timestamp('updated_at')
});

export const habitRelations = relations(habits, ({ many }) => ({
checks: many(habits)
}));

export const checks = pgTable('checks', {
id: serial('id').primaryKey(),
checked_at: date('date'),
habit_id: integer('habit_id')
});

export const checkRelations = relations(checks, ({ one }) => ({
habit: one(habits, {
fields: [checks.habit_id],
references: [habits.id]
})
}));
import { relations } from 'drizzle-orm';
import { serial, text, timestamp, pgTable, date, integer } from 'drizzle-orm/pg-core';

export const habits = pgTable('habits', {
id: serial('id').primaryKey(),
name: text('name'),
days_per_month: integer('days_per_month'),
created_at: timestamp('created_at'),
updated_at: timestamp('updated_at')
});

export const habitRelations = relations(habits, ({ many }) => ({
checks: many(habits)
}));

export const checks = pgTable('checks', {
id: serial('id').primaryKey(),
checked_at: date('date'),
habit_id: integer('habit_id')
});

export const checkRelations = relations(checks, ({ one }) => ({
habit: one(habits, {
fields: [checks.habit_id],
references: [habits.id]
})
}));
Here is my query
const data = await db.query.habits.findMany({
with: {
checks: true
}
});
const data = await db.query.habits.findMany({
with: {
checks: true
}
});
Not sure what I'm doing wrong. Thank you!
2 Replies
Scott Tolinski
Scott TolinskiOP12mo ago
I felt like I was following https://orm.drizzle.team/docs/rqb#one-to-many to a T, but I'm sure something is off here
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Scott Tolinski
Scott TolinskiOP12mo ago
Doesn't seem to be an obvious syntax errors, no TS errors in the query or the schema I have also tried without snake_case and getting the same erorr just in case AH found it. checks: many(habits) -> checks: many(checks)
Want results from more Discord servers?
Add your server