siriate
siriate
DTDrizzle Team
Created by siriate on 1/2/2024 in #help
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",
}),
}));
6 replies