error: relation "xxx" already exists
Hello!
Every time I run a second
drizzle-kit up
I get the same error, on the same table every time. I need to completely wipe my database in between
error: relation "table_filters" already existsI went through all my relations and this doesn't have one except a FK:
export const tableFilters = pgTable(
"table_filters",
{
id: text("id").primaryKey(),
userId: varchar("user_id", {
length: 32,
})
.notNull()
.references(() => users.userId),
name: text("name").notNull(),
isDefault: boolean("is_default").default(false).notNull(),
target: text("target").notNull(),
filter: jsonb("filter").$type<Filter>().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow(),
},
(table) => ({
targetUserIdx: index("target_user_idx").on(table.target, table.userId),
}),
);
export const tableFilters = pgTable(
"table_filters",
{
id: text("id").primaryKey(),
userId: varchar("user_id", {
length: 32,
})
.notNull()
.references(() => users.userId),
name: text("name").notNull(),
isDefault: boolean("is_default").default(false).notNull(),
target: text("target").notNull(),
filter: jsonb("filter").$type<Filter>().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow(),
},
(table) => ({
targetUserIdx: index("target_user_idx").on(table.target, table.userId),
}),
);
"drizzle-kit": "^0.30.2",
"drizzle-orm": "^0.38.4",
"drizzle-kit": "^0.30.2",
"drizzle-orm": "^0.38.4",
1 Reply
Here are the full logs after I've wiped the database:
> dotenv drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/me/my-app/apps/nextjs/drizzle.config.ts'
(node:34566) ExperimentalWarning: CommonJS module /Users/me/my-app/apps/nextjs/drizzle.config.ts is loading ES Module /Users/me/my-app/apps/nextjs/src/env.mjs using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Using 'pg' driver for database querying
[✓] Pulling schema from database...
[✓] Changes applied
> dotenv drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/me/my-app/apps/nextjs/drizzle.config.ts'
(node:34566) ExperimentalWarning: CommonJS module /Users/me/my-app/apps/nextjs/drizzle.config.ts is loading ES Module /Users/me/my-app/apps/nextjs/src/env.mjs using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Using 'pg' driver for database querying
[✓] Pulling schema from database...
[✓] Changes applied
> dotenv drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/me/my-app/apps/nextjs/drizzle.config.ts'
(node:34627) ExperimentalWarning: CommonJS module /Users/me/my-app/apps/nextjs/drizzle.config.ts is loading ES Module /Users/me/my-app/apps/nextjs/src/env.mjs using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Using 'pg' driver for database querying
[✓] Pulling schema from database...
error: relation "table_filters" already exists
at /Users/me/my-app/node_modules/pg-pool/index.js:45:11
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.query (/Users/me/my-app/apps/nextjs/node_modules/drizzle-kit/bin.cjs:64475:26)
at async pgPush (/Users/me/my-app/apps/nextjs/node_modules/drizzle-kit/bin.cjs:67954:13)
at async Object.handler (/Users/me/my-app/apps/nextjs/node_modules/drizzle-kit/bin.cjs:76964:9)
at async run (/Users/me/my-app/apps/nextjs/node_modules/drizzle-kit/bin.cjs:76221:7) {
length: 107,
severity: 'ERROR',
code: '42P07',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'heap.c',
line: '1149',
routine: 'heap_create_with_catalog'
}
> dotenv drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/me/my-app/apps/nextjs/drizzle.config.ts'
(node:34627) ExperimentalWarning: CommonJS module /Users/me/my-app/apps/nextjs/drizzle.config.ts is loading ES Module /Users/me/my-app/apps/nextjs/src/env.mjs using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Using 'pg' driver for database querying
[✓] Pulling schema from database...
error: relation "table_filters" already exists
at /Users/me/my-app/node_modules/pg-pool/index.js:45:11
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.query (/Users/me/my-app/apps/nextjs/node_modules/drizzle-kit/bin.cjs:64475:26)
at async pgPush (/Users/me/my-app/apps/nextjs/node_modules/drizzle-kit/bin.cjs:67954:13)
at async Object.handler (/Users/me/my-app/apps/nextjs/node_modules/drizzle-kit/bin.cjs:76964:9)
at async run (/Users/me/my-app/apps/nextjs/node_modules/drizzle-kit/bin.cjs:76221:7) {
length: 107,
severity: 'ERROR',
code: '42P07',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'heap.c',
line: '1149',
routine: 'heap_create_with_catalog'
}