Description
Summary: Sequelize generates invalid SQL with an unsupported USING clause when syncing ENUM columns with comments in PostgreSQL.
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Bug Description
When syncing a model using sequelize.sync({ alter: true, force: false }), Sequelize generates invalid SQL if the model contains an ENUM column with a comment.
This causes a PostgreSQL syntax error:
COMMENT ON COLUMN ... USING ...
The USING clause is not valid in a COMMENT statement.
Reproducible Example
Minimal example model:
const Appointment = sequelize.define('Appointment', {
status: {
type: DataTypes.ENUM('pending', 'confirmed', 'cancelled', 'completed'),
allowNull: false,
defaultValue: 'pending',
comment: 'Appointment lifecycle status',
}
}, {
tableName: 'appointments'
});
Sync code:
sequelize.sync({ alter: true, force: false })
.then(() => console.log("Synced!"))
.catch(err => console.error("Sync error:", err));
The error that occurs:
SequelizeDatabaseError: syntax error at or near "USING"
What do you expect to happen?
Expected behavior:
Sequelize should generate valid SQL to add or alter the comment without the USING clause:
COMMENT ON COLUMN "appointments"."status" IS 'Appointment lifecycle status';
What is actually happening?
This issue appears only during sync({ alter: true, force: false }) because Sequelize tries to alter the column comment by including an invalid USING clause, which PostgreSQL does not support for COMMENT statements.
Sequelize generates the following invalid SQL when altering a column:
COMMENT ON COLUMN "appointments"."status" IS 'Appointment lifecycle status' USING ("status"::"public"."enum_appointments_status");
which causes this PostgreSQL error:
PostgreSQL error: syntax error at or near "USING"
Note: The USING clause is only valid in an ALTER COLUMN ... TYPE ... USING statement, not in a COMMENT ON statement.
Also, when using force: true (which drops and recreates tables), this error does not occur because Sequelize skips the ALTER COLUMN statement.
Screenshot of error :
Environment
- Sequelize version: 6.37.5
- Node.js version: v20.12.2
- TypeScript version: Not applicable
- Database: PostgreSQL (version unknown)
- Connector library: pg 8.13.1
- pgAdmin version: 8.13
Would you be willing to resolve this issue by submitting a Pull Request?
[x] Yes, I have the time and I know how to start.
☑ Yes, I have the time but I will need guidance.
[x] No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
[x] No, I don't have the time and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.


Activity
axolo commentedon Oct 10, 2025
+1
define model:
generate sql:
error:
fix(postgres): keep USING clause out of COMMENT ON COLUMN when alteri…
fix(postgres): keep USING clause out of COMMENT ON COLUMN when alteri…
fix(postgres): keep USING clause out of COMMENT ON COLUMN when alteri…
fix(postgres): keep USING clause out of COMMENT ON COLUMN when alteri…
fix(postgres): keep USING clause out of COMMENT ON COLUMN when alteri…