PostgresError: relation "public.artist" does not exist

Hi, I'm new to drizzle. I am getting this error while trying to apply migrations,
 npm run db:migrate

> [email protected] db:migrate
> tsx src/lib/database/migrate.ts

{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '131',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '217',
routine: 'transformCreateStmt'
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: relation "public.artist" does not exist
at ErrorResponse (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:788:26)
at handle (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42P01',
where: 'SQL statement "ALTER TABLE "album" ADD CONSTRAINT "album_artist_id_artist_id_fk" FOREIGN KEY ("artist_id") REFERENCES "public"."artist"("id") ON DELETE cascade ON UPDATE no action"\n' +
'PL/pgSQL function inline_code_block line 2 at SQL statement',
file: 'namespace.c',
line: '427',
routine: 'RangeVarGetRelidExtended'
}

Node.js v18.19.0
 npm run db:migrate

> [email protected] db:migrate
> tsx src/lib/database/migrate.ts

{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '131',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '217',
routine: 'transformCreateStmt'
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: relation "public.artist" does not exist
at ErrorResponse (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:788:26)
at handle (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42P01',
where: 'SQL statement "ALTER TABLE "album" ADD CONSTRAINT "album_artist_id_artist_id_fk" FOREIGN KEY ("artist_id") REFERENCES "public"."artist"("id") ON DELETE cascade ON UPDATE no action"\n' +
'PL/pgSQL function inline_code_block line 2 at SQL statement',
file: 'namespace.c',
line: '427',
routine: 'RangeVarGetRelidExtended'
}

Node.js v18.19.0
69 Replies
CyberCipher
CyberCipherOP3mo ago
"drizzle-orm": "^0.33.0",
"drizzle-kit": "^0.24.0",
"drizzle-orm": "^0.33.0",
"drizzle-kit": "^0.24.0",
CyberCipher
CyberCipherOP3mo ago
I found this, https://github.com/t3-oss/create-t3-turbo/issues/511 which said to remove s from table names, which I already tried but no luck.
GitHub
bug: drizzle adapter with postgres ends with `error: relation "t3tu...
Provide environment information System: OS: Windows 10 10.0.25300 CPU: (16) x64 AMD Ryzen 7 6800HS with Radeon Graphics Memory: 12.63 GB / 31.26 GB Binaries: Node: 20.5.1 - ~\AppData\Local\Volta\to...
CyberCipher
CyberCipherOP3mo ago
I have also tried creating,
const schema = pgSchema("core");
const schema = pgSchema("core");
then replacing all pgTable to schema.table, and I get this error,
 npm run db:migrate

> [email protected] db:migrate
> tsx src/lib/database/migrate.ts

{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '131',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '217',
routine: 'transformCreateStmt'
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: schema "core" does not exist
at ErrorResponse (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:788:26)
at handle (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '3F000',
where: `SQL statement "CREATE TYPE "core"."user_role" AS ENUM('ADMIN', 'USER')"\n` +
'PL/pgSQL function inline_code_block line 2 at SQL statement',
file: 'namespace.c',
line: '3051',
routine: 'get_namespace_oid'
}
 npm run db:migrate

> [email protected] db:migrate
> tsx src/lib/database/migrate.ts

{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '131',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '217',
routine: 'transformCreateStmt'
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: schema "core" does not exist
at ErrorResponse (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:788:26)
at handle (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///home/apoorv/repos/app/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '3F000',
where: `SQL statement "CREATE TYPE "core"."user_role" AS ENUM('ADMIN', 'USER')"\n` +
'PL/pgSQL function inline_code_block line 2 at SQL statement',
file: 'namespace.c',
line: '3051',
routine: 'get_namespace_oid'
}
Can anyone help with this?
Angelelz
Angelelz3mo ago
You are trying to apply a migration to a database that is not in the state the migration script expects You might have dropped tables or otherwise changed the structure manually?
CyberCipher
CyberCipherOP3mo ago
I have tried deleting the migration directory and DB entirely and start from scratch multiple times still same error.
Angelelz
Angelelz3mo ago
If you deleted the migration directory, you should generate a new migration. You also have to make sure you drop the __drizzle_migrations table from the database as well Just so you know, you should not delete those files manually. There is a drop command when you want to start over
CyberCipher
CyberCipherOP3mo ago
I use use docker for postgresql and I ran docker system prune -fa to delete the container, volume and all, and also delete the migrations directory. So its almost like nothing ever happened.. after this I have to generate the migration again and then run migrate. Yes, I am aware I am only doing this because ATM its not working.
Darren
Darren3mo ago
youre creating a schema... but are you also exporting it? if you dont export it like table defintions, it won't get created, thus you see the error youre getting
CyberCipher
CyberCipherOP3mo ago
What do you mean by exporting? these are the 2 commands I run,
"db:generate": "drizzle-kit generate",
"db:migrate": "tsx src/lib/database/migrate.ts",
"db:generate": "drizzle-kit generate",
"db:migrate": "tsx src/lib/database/migrate.ts",
here is my migrate.ts file,
import "dotenv/config";
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

// for migrations
const migrationClient = postgres(process.env.DATABASE_URL as string, { max: 1 });

async function main() {
await migrate(drizzle(migrationClient), {
migrationsFolder: "./src/lib/database/migrations",
})

await migrationClient.end()
}

main()
import "dotenv/config";
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

// for migrations
const migrationClient = postgres(process.env.DATABASE_URL as string, { max: 1 });

async function main() {
await migrate(drizzle(migrationClient), {
migrationsFolder: "./src/lib/database/migrations",
})

await migrationClient.end()
}

main()
Darren
Darren3mo ago
you wrote this line
const schema = pgSchema("core");
const schema = pgSchema("core");
then tried to add a table to it... you would need
export const schema = pgSchema("core");
export const schema = pgSchema("core");
CyberCipher
CyberCipherOP3mo ago
ATM I am not using pgSchema I am using pgTable() But I can try using pgSchema again with export.
Darren
Darren3mo ago
in the last error log you posted that was the issue
CyberCipher
CyberCipherOP3mo ago
Yes, I said I tried that, and that also causes error. OK,
export const schema = pgSchema("core");
export const schema = pgSchema("core");
works.. Why does directly using pgTable not work?
Darren
Darren3mo ago
it does... but you were using a new schema in the second example you posted.. which needed to be created
CyberCipher
CyberCipherOP3mo ago
after every change I made I deleted the migrations directory and docker container hosting postgres DB. and ran generate and migrate after that..
Darren
Darren3mo ago
without seeing your actual code or errors no one can know what mistake you are making
CyberCipher
CyberCipherOP3mo ago
should I share my schema here?
CyberCipher
CyberCipherOP3mo ago
here is a video showing my deleting the db and migration directory and running generate and migrate command after that..
CyberCipher
CyberCipherOP3mo ago
in the video I am not using pgSchema but pgTable directly.
Darren
Darren3mo ago
can you show album table definition
CyberCipher
CyberCipherOP3mo ago
export const Album = pgTable("album", {
id: uuid("id").primaryKey().defaultRandom(),
title: varchar("title").notNull(),
release_date: date("release_date").notNull(),
thumbnail_url: varchar("thumbnail_url"),
artist_id: uuid("artist_id").references(() => Artist.id, { onDelete: "cascade" }).notNull(),
record_label_id: uuid('record_label_id').references(() => RecordLabel.id, { onDelete: "cascade" }).notNull(),
}, (table) => {
return {
artist_album_index: uniqueIndex("artist_index").on(table.artist_id, table.title),
record_label_index: uniqueIndex("record_label_index").on(table.record_label_id),
}
});
export const Album = pgTable("album", {
id: uuid("id").primaryKey().defaultRandom(),
title: varchar("title").notNull(),
release_date: date("release_date").notNull(),
thumbnail_url: varchar("thumbnail_url"),
artist_id: uuid("artist_id").references(() => Artist.id, { onDelete: "cascade" }).notNull(),
record_label_id: uuid('record_label_id').references(() => RecordLabel.id, { onDelete: "cascade" }).notNull(),
}, (table) => {
return {
artist_album_index: uniqueIndex("artist_index").on(table.artist_id, table.title),
record_label_index: uniqueIndex("record_label_index").on(table.record_label_id),
}
});
Darren
Darren3mo ago
Artist.id youre using capital letters RecordLabel.id
CyberCipher
CyberCipherOP3mo ago
variable name? they need to be lower case too?
Darren
Darren3mo ago
ok nm yh i glances without reading.. one sec how is the volume defined in your docker container, its not a shared volume right> whats in your drizzle config?
CyberCipher
CyberCipherOP3mo ago
volumes:
drizzle-db:

services:
drizzle-db:
container_name: drizzle-db
image: postgres:${POSTGRES_VERSION:-13}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-sonora}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-drizzle}
POSTGRES_USER: ${POSTGRES_USER:-drizzle}
ports:
- "5432:5432"
volumes:
- drizzle-db:/var/lib/postgresql/data:rw
volumes:
drizzle-db:

services:
drizzle-db:
container_name: drizzle-db
image: postgres:${POSTGRES_VERSION:-13}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-sonora}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-drizzle}
POSTGRES_USER: ${POSTGRES_USER:-drizzle}
ports:
- "5432:5432"
volumes:
- drizzle-db:/var/lib/postgresql/data:rw
Darren
Darren3mo ago
that is global volume no? drizzle-db it still exists after compose down
CyberCipher
CyberCipherOP3mo ago
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: "./src/lib/database/schema.ts",
out: "./src/lib/database/migrations",
dialect: "postgresql",
dbCredentials: {
url: process.env.DB_URL as string,
},
verbose: true,
strict: true
});
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: "./src/lib/database/schema.ts",
out: "./src/lib/database/migrations",
dialect: "postgresql",
dbCredentials: {
url: process.env.DB_URL as string,
},
verbose: true,
strict: true
});
I run docker-compose down -v , -v deletes the volume related to container too.
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
otherwise drizzle would have said about duplicates or something I suppose.
Darren
Darren3mo ago
no the sql is create if not exists when it fails can u look in your db see what it has
CyberCipher
CyberCipherOP3mo ago
inside the db?
Darren
Darren3mo ago
yeah the migrate fails
CyberCipher
CyberCipherOP3mo ago
I mean the migration hasn't run so how would the db exist?
Darren
Darren3mo ago
its got part way
CyberCipher
CyberCipherOP3mo ago
what query do I run inside the psql shell?
Darren
Darren3mo ago
ok tell you what.. before doing that.. do aa compose up and the n do a drizzle kit introspect
CyberCipher
CyberCipherOP3mo ago
 npm run drizzle -- introspect

> drizzle-kit introspect

No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/apoorv/repos/sonora/drizzle.config.ts'
Error Either connection "url" or "host", "database" are required for PostgreSQL database connection
 npm run drizzle -- introspect

> drizzle-kit introspect

No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/apoorv/repos/sonora/drizzle.config.ts'
Error Either connection "url" or "host", "database" are required for PostgreSQL database connection
its probably because url is from a env var..
Darren
Darren3mo ago
yeah you owuld need to add dotenv in there.. jsut temp paste it in
CyberCipher
CyberCipherOP3mo ago
import "dotenv/config";
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: "./src/lib/database/schema.ts",
out: "./src/lib/database/migrations",
dialect: "postgresql",
dbCredentials: {
url: process.env.DB_URL as string,
},
verbose: true,
strict: true
});
import "dotenv/config";
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: "./src/lib/database/schema.ts",
out: "./src/lib/database/migrations",
dialect: "postgresql",
dbCredentials: {
url: process.env.DB_URL as string,
},
verbose: true,
strict: true
});
right?
Darren
Darren3mo ago
no
CyberCipher
CyberCipherOP3mo ago
you mean paste the url in?
Darren
Darren3mo ago
yeah just temp for this cmd
CyberCipher
CyberCipherOP3mo ago
one sec
 npm run drizzle -- introspect

> drizzle-kit introspect

No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/apoorv/repos/sonora/drizzle.config.ts'
Pulling from ['public'] list of schemas

Using 'postgres' driver for database querying
[✓] 0 tables fetched
[✓] 0 columns fetched
[✓] 0 enums fetched
[✓] 0 indexes fetched
[✓] 0 foreign keys fetched

[i] No SQL generated, you already have migrations in project
[✓] You schema file is ready ➜ src/lib/database/migrations/schema.ts 🚀
[✓] You relations file is ready ➜ src/lib/database/migrations/relations.ts 🚀
 npm run drizzle -- introspect

> drizzle-kit introspect

No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/apoorv/repos/sonora/drizzle.config.ts'
Pulling from ['public'] list of schemas

Using 'postgres' driver for database querying
[✓] 0 tables fetched
[✓] 0 columns fetched
[✓] 0 enums fetched
[✓] 0 indexes fetched
[✓] 0 foreign keys fetched

[i] No SQL generated, you already have migrations in project
[✓] You schema file is ready ➜ src/lib/database/migrations/schema.ts 🚀
[✓] You relations file is ready ➜ src/lib/database/migrations/relations.ts 🚀
its has 0 records looks like
Darren
Darren3mo ago
ok can you show me generated sql from the last migration i nmigrations folder
CyberCipher
CyberCipherOP3mo ago
its huge.. probably has to use some pastebin thing .sql file right?
Darren
Darren3mo ago
ps did you do a compose down -v bthen up again before yopu introspect?
CyberCipher
CyberCipherOP3mo ago
no its running since I posted the video here
Darren
Darren3mo ago
then it should have tables in it..... as it breakpoints after each table.. the fks are added at teh end so .... in your migrations file migrations.ts can you temp paste the same url in there and not use the env
CyberCipher
CyberCipherOP3mo ago
import "dotenv/config";
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

// for migrations
const migrationClient = postgres(process.env.DATABASE_URL as string, { max: 1 });

async function main() {
await migrate(drizzle(migrationClient), {
migrationsFolder: "./src/lib/database/migrations",
})

await migrationClient.end()
}

main()
import "dotenv/config";
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

// for migrations
const migrationClient = postgres(process.env.DATABASE_URL as string, { max: 1 });

async function main() {
await migrate(drizzle(migrationClient), {
migrationsFolder: "./src/lib/database/migrations",
})

await migrationClient.end()
}

main()
this?
Darren
Darren3mo ago
yeah
CyberCipher
CyberCipherOP3mo ago
const migrationClient = postgres("postgres://drizzle:drizzle@localhost/sonora", { max: 1 });
const migrationClient = postgres("postgres://drizzle:drizzle@localhost/sonora", { max: 1 });
now run migrate?
Darren
Darren3mo ago
yh
CyberCipher
CyberCipherOP3mo ago
same error
 npm run db:migrate

> [email protected] db:migrate
> tsx src/lib/database/migrate.ts

{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '131',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '217',
routine: 'transformCreateStmt'
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: relation "public.artist" does not exist
at ErrorResponse (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:788:26)
at handle (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42P01',
where: 'SQL statement "ALTER TABLE "album" ADD CONSTRAINT "album_artist_id_artist_id_fk" FOREIGN KEY ("artist_id") REFERENCES "public"."artist"("id") ON DELETE cascade ON UPDATE no action"\n' +
'PL/pgSQL function inline_code_block line 2 at SQL statement',
file: 'namespace.c',
line: '427',
routine: 'RangeVarGetRelidExtended'
}

Node.js v18.19.0
 npm run db:migrate

> [email protected] db:migrate
> tsx src/lib/database/migrate.ts

{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '131',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '217',
routine: 'transformCreateStmt'
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: relation "public.artist" does not exist
at ErrorResponse (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:788:26)
at handle (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42P01',
where: 'SQL statement "ALTER TABLE "album" ADD CONSTRAINT "album_artist_id_artist_id_fk" FOREIGN KEY ("artist_id") REFERENCES "public"."artist"("id") ON DELETE cascade ON UPDATE no action"\n' +
'PL/pgSQL function inline_code_block line 2 at SQL statement',
file: 'namespace.c',
line: '427',
routine: 'RangeVarGetRelidExtended'
}

Node.js v18.19.0
Darren
Darren3mo ago
ok i need to see sql file then
CyberCipher
CyberCipherOP3mo ago
one sec.. here you go, https://termbin.com/rhr5
Darren
Darren3mo ago
i ran it as is, it worked
Darren
Darren3mo ago
No description
Darren
Darren3mo ago
there is something wrong with yoursetup
CyberCipher
CyberCipherOP3mo ago
hmm.. but I showed you everything.. drizzle config, schema, migrate script, pgsql docker container thing.. is there some version different for some tool here perhaps?
Darren
Darren3mo ago
well its just passing the sql to the db maybe the issue is with the postgres version if it doesnt havbe enum it would fail i guess
CyberCipher
CyberCipherOP3mo ago
what version of postgres you have?
Darren
Darren3mo ago
15 alpine
CyberCipher
CyberCipherOP3mo ago
let me change 13 to 15 then.. updated to 15.. still got same error,
 npm run db:migrate

> [email protected] db:migrate
> tsx src/lib/database/migrate.ts

node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: relation "public.artist" does not exist
at ErrorResponse (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:788:26)
at handle (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42P01',
where: 'SQL statement "ALTER TABLE "album" ADD CONSTRAINT "album_artist_id_artist_id_fk" FOREIGN KEY ("artist_id") REFERENCES "public"."artist"("id") ON DELETE cascade ON UPDATE no action"\n' +
'PL/pgSQL function inline_code_block line 2 at SQL statement',
file: 'namespace.c',
line: '428',
routine: 'RangeVarGetRelidExtended'
}

Node.js v18.19.0
 npm run db:migrate

> [email protected] db:migrate
> tsx src/lib/database/migrate.ts

node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

PostgresError: relation "public.artist" does not exist
at ErrorResponse (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:788:26)
at handle (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:474:6)
at Socket.data (file:///home/apoorv/repos/sonora/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42P01',
where: 'SQL statement "ALTER TABLE "album" ADD CONSTRAINT "album_artist_id_artist_id_fk" FOREIGN KEY ("artist_id") REFERENCES "public"."artist"("id") ON DELETE cascade ON UPDATE no action"\n' +
'PL/pgSQL function inline_code_block line 2 at SQL statement',
file: 'namespace.c',
line: '428',
routine: 'RangeVarGetRelidExtended'
}

Node.js v18.19.0
Darren
Darren3mo ago
as a test goto one opf the free db sites like supabase etc and jsut paste teh query in, you see there is nothing wrong with it
CyberCipher
CyberCipherOP3mo ago
deleted everything before running generate and migrate this time as well no I am not saying there is.. just wondering whats wrong with my setup then.. I mean using pgSchema it worked .. something is wrong when I use pgTable directly
Darren
Darren3mo ago
ohhh ofc dont you need to add the init scripts!!!!! youre using an image thats not setup so it has no schema try add an export const newSchema = pgSchema("public")
CyberCipher
CyberCipherOP3mo ago
but.. I have another one of my project using rust, in which I use diesel orm.. I never setup any schema with that.. perhaps they do that automatically and drizzle doesn't
Darren
Darren3mo ago
its all i can think of tbh
CyberCipher
CyberCipherOP3mo ago
also .. before I had simple table for user.. no FK or anything.. it worked that time.. I didn't setup any pgSchema that time either..
Darren
Darren3mo ago
then i dont know im sorry i cant help you
CyberCipher
CyberCipherOP3mo ago
hmm.. its ok I guess. I'll use pgSchema till I figure out what's happening then I guess.
Want results from more Discord servers?
Add your server