0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah i did that, and it hasn't changed anything. "Tags" variable is just a pointer to the model object, which holds the name of the table (Tag). Also, psql automatically adds the "s" in the end of the table name i think
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.