postgres error: type "serial" does not exist

I want to migrate my my changes but i get this error: type "serial" does not exist. This is my schema:
export const likes = pgTable("likes", {
postId: text("post_id").notNull().primaryKey(),
authorId: integer("author_id"),
});

export const posts = pgTable("post", {
id: serial("id").notNull().primaryKey(),
code: text("content"),
language: text("content"),
likes: integer("likes"),
authorId: integer("author_id")
.notNull()
.references(() => users.id),
});

export const users = pgTable("user", {
id: serial("id").notNull().primaryKey(),
username: text("username").unique(),
name: text("name"),
email: text("email").notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image"),
});
export const likes = pgTable("likes", {
postId: text("post_id").notNull().primaryKey(),
authorId: integer("author_id"),
});

export const posts = pgTable("post", {
id: serial("id").notNull().primaryKey(),
code: text("content"),
language: text("content"),
likes: integer("likes"),
authorId: integer("author_id")
.notNull()
.references(() => users.id),
});

export const users = pgTable("user", {
id: serial("id").notNull().primaryKey(),
username: text("username").unique(),
name: text("name"),
email: text("email").notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image"),
});
6 Replies
DieZitrone
DieZitroneOP14mo ago
my imports
import {
timestamp,
pgTable,
text,
primaryKey,
integer,
serial,
} from "drizzle-orm/pg-core";
import type { AdapterAccount } from "@auth/core/adapters";
import { relations } from "drizzle-orm";
import {
timestamp,
pgTable,
text,
primaryKey,
integer,
serial,
} from "drizzle-orm/pg-core";
import type { AdapterAccount } from "@auth/core/adapters";
import { relations } from "drizzle-orm";
Angelelz
Angelelz14mo ago
I'm not 100% sure but I believe you can't use serial in alter table statements.
Angelelz
Angelelz14mo ago
Take a look here. If you're attempting to migrate a column from any other type to serial: https://stackoverflow.com/questions/27307835/how-to-convert-primary-key-from-integer-to-serial
Stack Overflow
How to convert primary key from integer to serial?
In a Postgres 9.3 table I have an integer as primary key with automatic sequence to increment, but I have reached the maximum for integer. How to convert it from integer to serial? I tried: ALTER ...
DieZitrone
DieZitroneOP14mo ago
Its a new table, if that makes a difference. Any idea how I could fix it?
Angelelz
Angelelz14mo ago
I would just use integer as a workaround
DieZitrone
DieZitroneOP14mo ago
I fixed it, flushed my db, and added a new pk column using serial The other are text Ids now
Want results from more Discord servers?
Add your server