cannot push

error: relation "users" does not exist
at /home/ahmetkca/Projects/Oymak/overi/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:24545:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (/home/ahmetkca/Projects/Oymak/overi/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:25506:21)
at async pgSuggestions (/home/ahmetkca/Projects/Oymak/overi/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:25822:23)
at async Command.<anonymous> (/home/ahmetkca/Projects/Oymak/overi/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:63139:11) {
length: 104,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '31',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '1449',
routine: 'parserOpenTable'
}
error: relation "users" does not exist
at /home/ahmetkca/Projects/Oymak/overi/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:24545:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (/home/ahmetkca/Projects/Oymak/overi/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:25506:21)
at async pgSuggestions (/home/ahmetkca/Projects/Oymak/overi/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:25822:23)
at async Command.<anonymous> (/home/ahmetkca/Projects/Oymak/overi/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:63139:11) {
length: 104,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '31',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '1449',
routine: 'parserOpenTable'
}
9 Replies
Mykhailo
Mykhailo12mo ago
Hello, @HAL 9000! Could you please tell more about your problem? Usually this issue occurs when you create new table, forgot to push/migrate and then run drizzle studio (I saw your comment in another issue related to studio)
HAL 9000
HAL 9000OP12mo ago
@solo I sent my schema and unpushed migrations to this thread: https://discord.com/channels/1043890932593987624/1127209652694810816/1187820903963312229
Mykhailo
Mykhailo12mo ago
@HAL 9000 I see that you have changes that are not synced with your database (you haven't run the new migrations). Then, when you run Drizzle Studio, you encounter this error: error: relation "users" does not exist. Try running all migrations, as this will apply all the changes to your database. After that, run Drizzle Studio again
HAL 9000
HAL 9000OP12mo ago
I was acutally trying to push. I thought running push was applying all the migrations. here is my db.ts
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';

neonConfig.fetchConnectionCache = true;

const sql = neon(process.env.DATABASE_URL!);
const db = drizzle(sql);


export { db };
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';

neonConfig.fetchConnectionCache = true;

const sql = neon(process.env.DATABASE_URL!);
const db = drizzle(sql);


export { db };
and config:
import type { Config } from "drizzle-kit";
export default {
schema: "./lib/schema.ts",
out: "./drizzle",
driver: 'pg',
verbose: true,
dbCredentials: {
connectionString: process.env.DATABASE_URL!,
},
strict: true,
} satisfies Config;
import type { Config } from "drizzle-kit";
export default {
schema: "./lib/schema.ts",
out: "./drizzle",
driver: 'pg',
verbose: true,
dbCredentials: {
connectionString: process.env.DATABASE_URL!,
},
strict: true,
} satisfies Config;
I actualy need migrate.ts file. However, I don't think neon-db has migrator? I think that was the reason I skipped migrate.ts part I thought drizzle kit push would handle that
Mykhailo
Mykhailo12mo ago
import { neon, neonConfig } from '@neondatabase/serverless';
import 'dotenv/config';
import { drizzle } from 'drizzle-orm/neon-http';
import { migrate } from 'drizzle-orm/neon-http/migrator';

(async () => {
neonConfig.fetchConnectionCache = true;
const sql = neon(process.env.DRIZZLE_DATABASE_URL!);

const db = drizzle(sql);

await migrate(db, { migrationsFolder: './drizzle' });

console.log('Done');
})();
import { neon, neonConfig } from '@neondatabase/serverless';
import 'dotenv/config';
import { drizzle } from 'drizzle-orm/neon-http';
import { migrate } from 'drizzle-orm/neon-http/migrator';

(async () => {
neonConfig.fetchConnectionCache = true;
const sql = neon(process.env.DRIZZLE_DATABASE_URL!);

const db = drizzle(sql);

await migrate(db, { migrationsFolder: './drizzle' });

console.log('Done');
})();
you should use migrate function to run migrations btw, drizzle-kit push:{dialect} lets you push your schema changes directly to the database without generating any migrations files and does not require their use
HAL 9000
HAL 9000OP12mo ago
ok got it.
Mykhailo
Mykhailo12mo ago
Does it help you? If not, can you tell the steps to reproduce?
HAL 9000
HAL 9000OP12mo ago
so the flow is generate migrations and then run migrations?
Mykhailo
Mykhailo12mo ago
yes, it should work
Want results from more Discord servers?
Add your server