foreign key constraint cannot be implemented

/Users/daniel/Documents/Repos/Thatch/thatch-web/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:771
const error = Errors.postgres(parseError(x))
^
PostgresError: foreign key constraint "users_to_posts_user_id_users_id_fk" cannot be implemented
/Users/daniel/Documents/Repos/Thatch/thatch-web/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:771
const error = Errors.postgres(parseError(x))
^
PostgresError: foreign key constraint "users_to_posts_user_id_users_id_fk" cannot be implemented
import { relations } from "drizzle-orm";
import { pgTable, primaryKey, varchar } from "drizzle-orm/pg-core";

import { posts } from "./posts";
import { users } from "./users";

export const usersToPosts = pgTable(
"users_to_posts",
{
userId: varchar("user_id")
.notNull()
.references(() => users.id),
postId: varchar("post_id")
.notNull()
.references(() => posts.id),
},
(t) => ({
pk: primaryKey(t.userId, t.postId),
})
);

export const usersToPostsRelations = relations(usersToPosts, ({ one }) => ({
post: one(posts, {
fields: [usersToPosts.postId],
references: [posts.id],
}),
user: one(users, {
fields: [usersToPosts.userId],
references: [users.id],
}),
}));
import { relations } from "drizzle-orm";
import { pgTable, primaryKey, varchar } from "drizzle-orm/pg-core";

import { posts } from "./posts";
import { users } from "./users";

export const usersToPosts = pgTable(
"users_to_posts",
{
userId: varchar("user_id")
.notNull()
.references(() => users.id),
postId: varchar("post_id")
.notNull()
.references(() => posts.id),
},
(t) => ({
pk: primaryKey(t.userId, t.postId),
})
);

export const usersToPostsRelations = relations(usersToPosts, ({ one }) => ({
post: one(posts, {
fields: [usersToPosts.postId],
references: [posts.id],
}),
user: one(users, {
fields: [usersToPosts.userId],
references: [users.id],
}),
}));
1 Reply
Jokerz
JokerzOP2y ago
figured it out, it doesnt like the uuid column type, fine if i change back to serial
Want results from more Discord servers?
Add your server