我试着解决标题中的问题。PlanetScale还不支持外键。
这是我当前的schema:
export const users = mysqlTable("user", {
id: varchar("id", { length: 256 }).primaryKey(),
email: varchar("email", { length: 256 }).unique(),
username: varchar("username", { length: 256 }).unique(),
firstName: text("first_name"),
lastName: text("last_name"),
});
export const usersRelations = relations(users, ({ many }) => ({
followers: many(following, { relationName: "followers" }),
following: many(following, { relationName: "following" }),
}));
export const following = mysqlTable("usersFollowing", {
userId: varchar("user_id", { length: 255 }).primaryKey(),
followerId: varchar("follower_id", { length: 255 }).notNull(),
});
export const followingRelations = relations(following, ({ one }) => ({
userId: one(users, {
fields: [following.userId],
references: [users.id],
relationName: "user",
}),
followerId: one(users, {
fields: [following.followerId],
references: [users.id],
relationName: "follower",
}),
}));
字符串
但它说:
错误:没有足够的信息来推断关系“用户.关注者”
有人能帮忙吗?
1条答案
按热度按时间eufgjt7s1#
我解决了我的问题,这是代码:
字符串