[BUG]: error: type "serial" does not exist
What version of drizzle-orm are you using?
0.30.8
What version of drizzle-kit are you using?
0.20.16
Describe the Bug
After generating a migration with drizzle-kit, running drizzle-kit push:pg results in error: type "serial" does not exist
Schema:
export const someEntities = pgTable("some_entity", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
userId: text("userId").notNull().references(() => users.id),
})
Migration:
ALTER TABLE "some_entity" ALTER COLUMN "id" SET DATA TYPE serial;
Full error:
error: type "serial" does not exist
at /Users/xxx/Code/xxx/node_modules/drizzle-kit/bin.cjs:43518:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (/Users/xxx/Code/xxx/node_modules/drizzle-kit/bin.cjs:62439:21)
at async Command.<anonymous> (/Users/xxx/Code/xxx/node_modules/drizzle-kit/bin.cjs:66122:9) {
length: 89,
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
Expected behavior
Expect migration to be run and table alteration to complete successfully.
Environment & setup
macOS 14.4.1 Vercel Postgres: PostgreSQL 15 @vercel/postgres: 0.8.0
I'm also facing the same issue, @realmikesolo. However, I added the 'drizzle-kit' .
same problem
I also have this issue if you delete the table in the database it then works but you may want the data
i have the same issue
I'm facing the same issue.
error: type "serial" does not exist
at C:\Users\ADMIN\Desktop\my office\zuvy-server\node_modules\pg-pool\index.js:45:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.query (C:\Users\ADMIN\Desktop\my office\zuvy-server\node_modules\drizzle-kit\bin.cjs:71837:26)
at async pgPush (C:\Users\ADMIN\Desktop\my office\zuvy-server\node_modules\drizzle-kit\bin.cjs:74783:13)
at async Object.handler (C:\Users\ADMIN\Desktop\my office\zuvy-server\node_modules\drizzle-kit\bin.cjs:83642:9)
at async run (C:\Users\ADMIN\Desktop\my office\zuvy-server\node_modules\drizzle-kit\bin.cjs:82009:7) {
length: 89,
severity: 'ERROR',
code: '42704','
detail: undefined,
hint: undefined,
Any updates here?
Facing the same issue.
Same
Same issue here
+1
+1
+1
+1
+1
since "serial" is just a equivalent of CREATE SEQUENCE tablename_colname_seq; CREATE TABLE tablename ( colname integer NOT NULL DEFAULT nextval('tablename_colname_seq') ); ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname; as mentioned in this stack overflow thread, it cannot be used in an ALTER instruction, thus to resolve the issue you have to drop the table and bring it up with correct type instead of whatever else was in it's place. That should resolve the issue, at least it did for me.
There’s no need to drop the table, you can do the new column, drop column, rename column shenanigans instead.
Either way, it would be nice for Drizzle to handle this.
+1
There’s no need to drop the table, you can do the new column, drop column, rename column shenanigans instead.
What if the column is the primary key
This is not a bug, since serial is not a type 1: Postgres docs 2: Stack I solved it by editing my pgAdmin directly and then doing a npx drizzle-kit-pull, After setting the sequence you must change the type to integer for the record you are trying to change example: alter table customers alter column id type integer using(id::integer); This happens since databases in general I suppose don't let you change attributes from text to numbers so you have to do it manually this is risky if your db is populated obviously!