Drizzle kit schema migration with mysql ; Rerunning the entire schema

I use mysql2 as my database and when i run my migrate script "migrate": "drizzle-kit push:mysql --config drizzle.config.ts" this works fine but when i rerun my migrate script i get this error
Error: Duplicate key name 'company_id'
at PromiseConnection.query (/home/anasmohammed361/vs/fund-master/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:35481:26)
at Command.<anonymous> (/home/anasmohammed361/vs/fund-master/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:53292:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ER_DUP_KEYNAME',
errno: 1061,
sql: 'CREATE INDEX `company_id` ON `company` (`id`);',
sqlState: '42000',
sqlMessage: "Duplicate key name 'company_id'"
Error: Duplicate key name 'company_id'
at PromiseConnection.query (/home/anasmohammed361/vs/fund-master/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:35481:26)
at Command.<anonymous> (/home/anasmohammed361/vs/fund-master/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:53292:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ER_DUP_KEYNAME',
errno: 1061,
sql: 'CREATE INDEX `company_id` ON `company` (`id`);',
sqlState: '42000',
sqlMessage: "Duplicate key name 'company_id'"
2 Replies
Mohammed Anas
Mohammed AnasOP15mo ago
Only happens after the first migration , here is my schema for reference .
Mohammed Anas
Mohammed AnasOP15mo ago
My drizzle config
import type { Config } from "drizzle-kit";
import dotenv from "dotenv";
dotenv.config({path:'.env.local'});
export default {
schema: "./db/schema.ts",
out: "./db/migrations/",
dbCredentials: {
connectionString: process.env["DATABASE_URL"]!,
},
driver: "mysql2",
strict: true,
} satisfies Config;
import type { Config } from "drizzle-kit";
import dotenv from "dotenv";
dotenv.config({path:'.env.local'});
export default {
schema: "./db/schema.ts",
out: "./db/migrations/",
dbCredentials: {
connectionString: process.env["DATABASE_URL"]!,
},
driver: "mysql2",
strict: true,
} satisfies Config;
Want results from more Discord servers?
Add your server