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 defined
code: 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`);
No description
2 Replies
Eternal Mori
Eternal MoriOP9mo ago
My database and table in this example are using MariaDB with collation: utf8mb4_general_ci. When I use MySQL with utf8mb4_0900_ai_ci I dont experience this error.
Ben Koether
Ben Koether7mo ago
@A. Perkamentus did you ever get this to work with MariaDB? I'm running into the same issue.
Want results from more Discord servers?
Add your server