drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: error: type "serial" does not exist

Open nickrmurphy opened this issue 2 years ago • 24 comments

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

nickrmurphy avatar Apr 20 '24 23:04 nickrmurphy

I'm also facing the same issue, @realmikesolo. However, I added the 'drizzle-kit' .

giribabu22 avatar Jun 05 '24 08:06 giribabu22

same problem

blasdfaa avatar Jun 25 '24 16:06 blasdfaa

I also have this issue if you delete the table in the database it then works but you may want the data

GStudiosX2 avatar Aug 04 '24 00:08 GStudiosX2

i have the same issue

barrynorman avatar Aug 10 '24 23:08 barrynorman

I'm facing the same issue.

DevWedeloper avatar Aug 11 '24 09:08 DevWedeloper

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,

giribabu22 avatar Aug 23 '24 17:08 giribabu22

Any updates here?

timurkh-devstark avatar Aug 28 '24 13:08 timurkh-devstark

Facing the same issue.

HarjjotSinghh avatar Oct 22 '24 23:10 HarjjotSinghh

Same

spacerumsfeld-code avatar Oct 26 '24 20:10 spacerumsfeld-code

Same issue here

mmikhan avatar Nov 06 '24 20:11 mmikhan

+1

k3dom avatar Nov 09 '24 15:11 k3dom

+1

sebmor avatar Nov 14 '24 14:11 sebmor

+1

ricjohn-acosta avatar Nov 26 '24 21:11 ricjohn-acosta

+1

Friedrich482 avatar Dec 09 '24 00:12 Friedrich482

+1

Cedrickkk avatar Jan 30 '25 14:01 Cedrickkk

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.

Kartonowy avatar Feb 17 '25 15:02 Kartonowy

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.

typeofweb avatar Feb 18 '25 07:02 typeofweb

+1

mrgulc avatar Apr 16 '25 07:04 mrgulc

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

maxktz avatar Apr 18 '25 07:04 maxktz

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!

HikariKojima avatar Apr 19 '25 10:04 HikariKojima