drizzle-team / drizzle-team/drizzle-orm

[DOCS]: Getting Started: serial().primaryKey() is a bad example for MySQL/MariaDB

Open
#4,271 3 comments 0 reactions 0 assignees View on GitHub
db/mysql docs docs/improvements
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Enhancement hasn't been filed before.

- [x] I have verified this enhancement I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

Here: https://orm.drizzle.team/docs/get-started/mysql-new#step-4---create-a-table the docs suggest

```ts
import { int, mysqlTable, serial, varchar } from 'drizzle-orm/mysql-core';

export const usersTable = mysqlTable('users_table', {
id: serial().primaryKey(),
name: varchar({ length: 255 }).notNull(),
age: int().notNull(),
email: varchar({ length: 255 }).notNull().unique(),
});
```

Which I tried verbatim, which comes out as

```sql
CREATE TABLE users_table (
id serial AUTO_INCREMENT NOT NULL,
name varchar(255) NOT NULL,
age int NOT NULL,
email varchar(255) NOT NULL,
CONSTRAINT users_table_id PRIMARY KEY(id),
CONSTRAINT users_table_email_unique UNIQUE(email)
);
```

But if you check the docs https://dev.mysql.com/doc/refman/8.4/en/numeric-type-syntax.html it says

> SERIAL is an alias for `BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE`.

So effectively `serial AUTO_INCREMENT` is trying to set `AUTO_INCREMENT` twice, which is a syntax error.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.