简体   繁体   中英

Sequelize throwing invalid input syntax for integer ""

I've got a model definition here:

const Tags = sequelize.define('Tag', {
    name: {
        type: DataTypes.TEXT,
        allowNull: false,
    },
    adminOnly: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
    },
})

And 2 endpoints which create and fetch objects from the DB (psql)

const tags = await Tags.findAll()

But this line fails. What i get is

UnhandledPromiseRejectionWarning: SequelizeDatabaseError: invalid input syntax for integer: "tags"

While

await Tag.create({name: name, isStock: isStock ?? false})

works perfectly fine.

When i log in to the psql console and do select over the table i have no problems either.

As your own example states, Tag.create works but Tags.findAll doesn't. Have you tried Tag.findAll()? I use init for defining models but IIRC you should match the variable name to the table name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM