Scott Tolinski
Scott Tolinski
DTDrizzle Team
Created by Scott Tolinski on 1/4/2024 in #help
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!
5 replies