drizzle-kit push error: Multiple primary key defined
When executing the "pnpm drizzle-kit push:mysql" command for the first time on an empty database, there are no errors. However, when I push again, I encounter the following error:
code: ER_MULTIPLE_PRI_KEY
errno: 1068
sql: ALTER TABLE `accounts` ADD PRIMARY KEY(`id`);
message: Multiple primary key definedcode: ER_MULTIPLE_PRI_KEY
errno: 1068
sql: ALTER TABLE `accounts` ADD PRIMARY KEY(`id`);
message: Multiple primary key defined// schema.ts
import { mysqlTable as table, varchar } from "drizzle-orm/mysql-core";
export const accounts = table("accounts", {
id: varchar("id", { length: 36 }).primaryKey(),
type: varchar("type", { length: 191 }).notNull(),
});// schema.ts
import { mysqlTable as table, varchar } from "drizzle-orm/mysql-core";
export const accounts = table("accounts", {
id: varchar("id", { length: 36 }).primaryKey(),
type: varchar("type", { length: 191 }).notNull(),
});// drizzle.config.ts
import { defineConfig } from "drizzle-kit";
export default defineConfig({
schema: "./db/schema.ts",
driver: "mysql2",
dbCredentials: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
},
verbose: true,
});// drizzle.config.ts
import { defineConfig } from "drizzle-kit";
export default defineConfig({
schema: "./db/schema.ts",
driver: "mysql2",
dbCredentials: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
},
verbose: true,
});// When first executing the command, this is the query
CREATE TABLE `accounts` (
`id` varchar(36) NOT NULL,
`type` varchar(191) NOT NULL,
CONSTRAINT `accounts_id` PRIMARY KEY(`id`)
);// When first executing the command, this is the query
CREATE TABLE `accounts` (
`id` varchar(36) NOT NULL,
`type` varchar(191) NOT NULL,
CONSTRAINT `accounts_id` PRIMARY KEY(`id`)
);// When executing for the second time, this query is produced
ALTER TABLE `accounts` ADD PRIMARY KEY(`id`);// When executing for the second time, this query is produced
ALTER TABLE `accounts` ADD PRIMARY KEY(`id`);