There is not enough information to infer relation error

I have such schemas (code below) with relations and when I try to load Drizzle Studio, to preview database, I get such error: There is not enough information to infer relation "__public__.courses.tests". Can you please help me to solve this issue, since I have no idea how to do it?
// schema/courses.ts
export const courses = pgTable('courses', {
id: serial('id').primaryKey(),
number: integer('number').notNull().unique()
})

export const courseRelations = relations(courses, ({ many }) => ({
tests: many(tests)
}))
// schema/courses.ts
export const courses = pgTable('courses', {
id: serial('id').primaryKey(),
number: integer('number').notNull().unique()
})

export const courseRelations = relations(courses, ({ many }) => ({
tests: many(tests)
}))
// schema/tests.ts
export const tests = pgTable('tests', {
id: serial('id').primaryKey(),
createdAt: timestamp('created_at').defaultNow(),
updatedAt: timestamp('updated_at').defaultNow(),
name: varchar('name', { length: 255 }).notNull(),
isVerified: boolean('is_verified').default(false),
universityId: integer('university_id').references(() => universities.id, { onDelete: 'cascade' }).notNull(),
facultyId: integer('faculty_id').references(() => faculties.id, { onDelete: 'cascade' }).notNull(),
subjectId: integer('subject_id').references(() => subjects.id, { onDelete: 'cascade' }).notNull(),
courseId: integer('course_id').references(() => courses.id, { onDelete: 'cascade' }).notNull()
})

export const testRelations = relations(tests, ({ one, many }) => ({
course: one(courses),
university: one(universities),
faculty: one(faculties),
subject: one(subjects),
user: one(users),
questions: many(questions),
}));
// schema/tests.ts
export const tests = pgTable('tests', {
id: serial('id').primaryKey(),
createdAt: timestamp('created_at').defaultNow(),
updatedAt: timestamp('updated_at').defaultNow(),
name: varchar('name', { length: 255 }).notNull(),
isVerified: boolean('is_verified').default(false),
universityId: integer('university_id').references(() => universities.id, { onDelete: 'cascade' }).notNull(),
facultyId: integer('faculty_id').references(() => faculties.id, { onDelete: 'cascade' }).notNull(),
subjectId: integer('subject_id').references(() => subjects.id, { onDelete: 'cascade' }).notNull(),
courseId: integer('course_id').references(() => courses.id, { onDelete: 'cascade' }).notNull()
})

export const testRelations = relations(tests, ({ one, many }) => ({
course: one(courses),
university: one(universities),
faculty: one(faculties),
subject: one(subjects),
user: one(users),
questions: many(questions),
}));
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server