I've done db:generate and db:push, but nothing happens.

import * as dotenv from 'dotenv';
import type { Config } from 'drizzle-kit';

dotenv.config();

export default {
schema: './src/**/schema.ts',
out: './drizzle',
driver: 'pg',
dbCredentials: { connectionString: process.env.DB_CLIENT_URL || '' },
} satisfies Config;
import * as dotenv from 'dotenv';
import type { Config } from 'drizzle-kit';

dotenv.config();

export default {
schema: './src/**/schema.ts',
out: './drizzle',
driver: 'pg',
dbCredentials: { connectionString: process.env.DB_CLIENT_URL || '' },
} satisfies Config;
1 Reply
Mykhailo
Mykhailo12mo ago
Hello, @sizzF. Could you tell us more about your problem and steps that you did? I followed these steps and everything worked for me 1. Declared the same drizzle.config.ts as you "drizzle.config.ts"
import * as dotenv from 'dotenv';
import type { Config } from 'drizzle-kit';

dotenv.config();

export default {
schema: './src/**/schema.ts',
out: './drizzle',
driver: 'pg',
dbCredentials: { connectionString: process.env.DB_CLIENT_URL || '' },
} satisfies Config;
import * as dotenv from 'dotenv';
import type { Config } from 'drizzle-kit';

dotenv.config();

export default {
schema: './src/**/schema.ts',
out: './drizzle',
driver: 'pg',
dbCredentials: { connectionString: process.env.DB_CLIENT_URL || '' },
} satisfies Config;
2. Declared schema in src/db folder "src/db/schema.ts"
import { pgTable, serial, text } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
description: text('description').notNull(),
});
import { pgTable, serial, text } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
description: text('description').notNull(),
});
3. Then I ran npx drizzle-kit push:db to apply changes directly to the database, so the users table was created. (Also, you can skip this step and just generate migrations, but then you have to run migrations to apply changes to the database) 4. Then I ran the npx drizzle-kit generate:pg command, and it generated a migration file with snapshots, which we can find in the drizzle folder in your project's root directory. This is our migration file
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"description" text NOT NULL
);
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"description" text NOT NULL
);
Want results from more Discord servers?
Add your server