DT
Drizzle Team•11mo ago
siriate

Error: There is not enough information to infer relation using Bun / SQLite

Hey there, I cannot seem to resolve the Error: There is not enough information to infer relation "__public__.users.accounts" error while making a simple one 2 many relation using Bun / SQLite. I've looked at all the problems in the help channel regarding this and I still cannot understand what is the issue. Could somebody help me out?
import { relations } from "drizzle-orm";
import { sqliteTable, text, index } from "drizzle-orm/sqlite-core";
import { ulid } from "ulid";

export const users = sqliteTable("users", {
id: text("id")
.primaryKey()
.$defaultFn(() => ulid()),
});

export const usersRelations = relations(users, ({ many }) => ({
accounts: many(users, { relationName: "user_accounts" }),
}));

export const accounts = sqliteTable(
"accounts",
{
id: text("id")
.primaryKey()
.$defaultFn(() => ulid()),
userId: text("user_id").references(() => users.id),
},
(table) => ({
userIdx: index("user_idx").on(table.userId),
})
);

export const accountsRelations = relations(accounts, ({ one }) => ({
user: one(users, {
fields: [accounts.userId],
references: [users.id],
relationName: "user_accounts",
}),
}));
import { relations } from "drizzle-orm";
import { sqliteTable, text, index } from "drizzle-orm/sqlite-core";
import { ulid } from "ulid";

export const users = sqliteTable("users", {
id: text("id")
.primaryKey()
.$defaultFn(() => ulid()),
});

export const usersRelations = relations(users, ({ many }) => ({
accounts: many(users, { relationName: "user_accounts" }),
}));

export const accounts = sqliteTable(
"accounts",
{
id: text("id")
.primaryKey()
.$defaultFn(() => ulid()),
userId: text("user_id").references(() => users.id),
},
(table) => ({
userIdx: index("user_idx").on(table.userId),
})
);

export const accountsRelations = relations(accounts, ({ one }) => ({
user: one(users, {
fields: [accounts.userId],
references: [users.id],
relationName: "user_accounts",
}),
}));
4 Replies
Angelelz
Angelelz•11mo ago
What query is causing this error?
siriate
siriateOP•11mo ago
I am not sure, I am just attempting to launch the drizzle-kit studio and this is what happens. The --verbose flag also does not add any logs.
Angelelz
Angelelz•11mo ago
I think you have a mistake:
export const usersRelations = relations(users, ({ many }) => ({
accounts: many(accounts, { relationName: "user_accounts" }), // <-- many(accounts)
}));
export const usersRelations = relations(users, ({ many }) => ({
accounts: many(accounts, { relationName: "user_accounts" }), // <-- many(accounts)
}));
siriate
siriateOP•11mo ago
That was it 🤠
Want results from more Discord servers?
Add your server