Skip to content

findOrCreate and MySQL sql_mode NO_AUTO_VALUE_ON_ZERO #5493

@riemannzeta

Description

@riemannzeta

Just a note to anybody else who ends up scratching their head on this one.

Was getting the following

ame: 'SequelizeUniqueConstraintError',
message: 'Validation error',
errors:
[ { message: 'PRIMARY must be unique',
type: 'unique violation',
path: 'PRIMARY',
value: '0' } ],
fields: { PRIMARY: '0' } }

DESPITE the fact that my table was setup with an auto_increment id field (normally this is the problem for most people).

Sequelize was auto-generating an INSERT query with the id field set to value DEFAULT. Apparently DEFAULT means 0 to MySQL, and 0 (when that sql_mode is on) does not trigger an autoincrement.

I understand that this setting is on for my server for security reasons, so not sure whether or not there is a change that could be implemented in the ORM to avoid this... like I said, just a heads up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).staletype: bugDEPRECATED: replace with the "bug" issue type

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions