Error "type 'serial' does not exist"

See original GitHub issue

Issue Description

I getting error type "serial" does not exist

What are you doing?

// postgres.js
const sql = new Sequelize(db, username, password, {
  host,
  port,
  dialect: 'postgres',
  dialectOptions: {
    ssl: false
  },
  logging: false,

  define: {
    timestamps: false,
    charset: 'utf8'
  }
});

sql
  .sync({ alter: true })
  .catch((err) =>
    logger.error(
      `[PostgreSQL]: Unable to the sync tables from server;
      ${err.message}
      ${err.parent && err.parent.sql ? '; with these SQL Query' : ''}
      ${err.parent && err.parent.sql ? '\n' : ''}
      ${(err.parent && err.parent.sql) || ''}`
    )
  )
  .then(() => sql.authenticate())
  .then(() =>
    logger.info('[PostgreSQL]: Connection has been established successfully.')
  )
  .catch((err) =>
    logger.error(
      `[PostgreSQL]: Unable to connect to the database
      ${err.message}`
    )
  );

export default sql;

// the file error happening
import DataTypes from 'sequelize';
import { v4 as uuidv4 } from 'uuid';
import sequelize from '../connections/postgres.js';

export default sequelize.define(
  'Order',
  {
    id: {
      type: DataTypes.UUID,
      defaultValue() {
        return uuidv4();
      },
      primaryKey: true
    },
    seqNo: {
      type: DataTypes.INTEGER,
      autoIncrement: true
    },
    description: {
      type: DataTypes.STRING,
      allowNull: false
    }
  },
  {
    freezeTableName: true,
    // define the table's name
    tableName: 'orders'
  }
);

What do you expect to happen?

Successfully sync, altering table

What is actually happening?

[PostgreSQL]: Unable to the sync tables from server;
      type "serial" does not exist
      ; with these SQL Query
      

      ALTER TABLE "orders" ALTER COLUMN "seqNo" DROP NOT NULL;ALTER TABLE "orders" ALTER COLUMN "seqNo" DROP DEFAULT;ALTER TABLE "orders" ALTER COLUMN "seqNo" TYPE  SERIAL;
[PostgreSQL]: Connection has been established successfully.

Additional context

Add any other context or screenshots about the feature request here.

Environment

  • Sequelize version: v6.5.0
  • Node.js version: v15.13.0
  • Operating System: macOS Catalina 10.15.7
  • If TypeScript related: TypeScript version: XXX

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don’t know, I was using Postgres, with pg@8.5.1 and pg-hstore@2.x versions and database version postgres@12

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don’t know how to start, I would need guidance.
  • No, I don’t have the time, although I believe I could do it if I had the time…
  • No, I don’t have the time and I wouldn’t even know how to start.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ephyscommented, Mar 29, 2022

Use the 👍 reaction on the initial post instead 😃 we can use it to sort by most requested issue

0reactions
Zaggermeistercommented, Mar 29, 2022

Also running into this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alter data type of a column to serial - sql - Stack Overflow
Look into postgresql documentation of datatype serial. Serial is only short hand. CREATE TABLE tablename ( colname SERIAL );.
Read more >
[GENERAL] ALTER TABLE with TYPE serial does not work
I have a short question to psql. postgres=# ALTER TABLE tab1 ALTER COLUMN nr TYPE serial; ERROR: type "serial" does not exist postgres=#...
Read more >
Re: ALTER TABLE with TYPE serial does not work - PostgreSQL
Why does this not work: > > postgres=# ALTER TABLE tab1 ALTER COLUMN nr TYPE serial; > ERROR: type "serial" does not exist....
Read more >
How to change data type of a primary key? : r/PostgreSQL
The table has data. I want to change the datatype from "int4" to "serial4". But when I do that I get an error...
Read more >
Serial Type Columns in PostgreSQL - Atlas
ALTER TABLE t ALTER COLUMN c TYPE serial ; ERROR: type "serial" does not exist. We can achieve this by manually creating a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found