© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
2 replies
Pieter

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`);
Schermafbeelding_2024-03-16_om_18.30.01.png
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Drizzle-kit Multiple primary key defined issue
Drizzle TeamDTDrizzle Team / help
2y ago
Multiple primary key defined
Drizzle TeamDTDrizzle Team / help
3y ago
drizzle-kit push error
Drizzle TeamDTDrizzle Team / help
2y ago
drizzle push and primary key order
Drizzle TeamDTDrizzle Team / help
3y ago