error: relation "X" does not exist
Hi I've been trying for awhile and can't seem to figure this out. I converted from prisma to use Drizzle. It works locally in my docker container but when I build my TS project then try run it or deploy it I get the following error...
error: relation "tours" does not exist
export const tours = pgTable("tours", {
id: uuid("id").defaultRandom().primaryKey().notNull(),
sport: uuid("sport").notNull(),
fullName: varchar("full_name", { length: 255 }).notNull(),
name: varchar("name", { length: 255 }).notNull(),
slug: varchar("slug", { length: 255 }).notNull(),
logo: varchar("logo", { length: 255 }),
},
(table) => {
return {
slugUnique: uniqueIndex("tours_slug_unique").using("btree", table.slug.asc().nullsLast()),
toursSportForeign: foreignKey({
columns: [table.sport],
foreignColumns: [sports.id],
name: "tours_sport_foreign"
}),
}
});
// When I call this I get error: relation "tours" does not exist
const tour = await db.query.tours.findFirst({
where: eq(tours.slug, 'pga-tour'),
});
2 Replies
I can run the query in drizzle studio, something must happen when my TS app gets built eek
I think i've got it working? I changed my db.ts file to use the connectionString instead of passing in host/port/.. etc.
connectionString does have ?schema=public at the end as well, so maybe try that 🤷♂️
import { drizzle } from 'drizzle-orm/node-postgres';
import { Client } from 'pg';
import * as schema from './schema';
export const client = new Client({
connectionString: process.env.DATABASE_URL!,
// host: process.env.DB_HOST!,
// port: Number(process.env.DB_PORT!),
// user: process.env.DB_USERNAME!,
// password: process.env.DB_PASSWORD!,
// database: process.env.DB_NAME!,
});
export const db = drizzle(client, { schema });