Repository navigation
Labels
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).type: bugDEPRECATED: replace with the "bug" issue type
Description
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
[email protected]and[email protected]versions and database versionpostgres@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.
Reacted by Sardorkhuja Tukhtakhodjaev, Zaggermeister, Guilherme Kairalla Kolotelo, Eugene Girtcius, seantalbot-jisc, Hamed Mohammadzadeh, nikto_b, Andrew Pierno, b-fett, Nick-Beam and 11 more
Metadata
Metadata
Assignees
Labels
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).type: bugDEPRECATED: replace with the "bug" issue type
Activity
Khuzha commentedon Oct 14, 2021
have the same issue
dalisoft commentedon Oct 17, 2021
It's my code bug.
autoIncrementshould be either primary or unique to be error-free. May be another case triggered for another codebasegithub-actions commentedon Oct 27, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
nziranzizacb commentedon Mar 5, 2022
Just facing this issue
ephys commentedon Mar 7, 2022
Looks like
SERIALcannot be used inALTER COLUMN, only inCREATE TABLE. Just tested with postgres 12We'd need to change it to
Zaggermeister commentedon Mar 29, 2022
ephys commentedon Mar 29, 2022
Use the 👍 reaction on the initial post instead :) we can use it to sort by most requested issue
john-easci commentedon Jul 31, 2024
I just ran into this... somebody wanted a GUID for the key, but to have an autoincrement alongside to be human-readable. It worked in code, but the migration failed due to the issues above.
So instead of waiting for a fix which may never happen, I added the following as a workaround:
Ugly because it requires another DB call (and you have to make sure your table is set up properly, while also creating a potential issue with deleted rows), but seems to have done the job for now, and maybe it helps the next guy who has this issue.