2

I am working with node, express and sequelize (I'm pretty new with all these three) and I'm getting "Unknown column 'productTeam' in 'field list'" in what I think is the simplest possible scenario:

In my backend code, I have the following:

    const repos = await ScasRepo.findAll(
        {
            where: {"productId": productId}
        }
    )

I can see that the generated query is as follows:

Executing (default):
SELECT `id`, `productTeam`, `productId`
FROM `ScasRepos` AS `ScasRepo`
WHERE `ScasRepo`.`productId` = '10519';

And this is what my table looks like:


mysql> describe ScasRepos;
+----------------+--------------+------+-----+---------+----------------+
| Field          | Type         | Null | Key | Default | Extra          |
+----------------+--------------+------+-----+---------+----------------+
| id             | int          | NO   | PRI | NULL    | auto_increment |
| productId      | int          | YES  |     | NULL    |                |
| productTeam    | varchar(255) | YES  |     | NULL    |                |
+----------------+--------------+------+-----+---------+----------------+

As you can see, the productTeam field is defined in the table, so why am I getting an error message saying "Unknown column 'productTeam' in 'field list'"?

Any insight is appreciated!

Xar
  • 7,572
  • 19
  • 56
  • 80
  • 1
    Note that the generated query is filtering for `productId = '10519'`, while the productId should be an integer, not a string. I doubt this causes the error you are getting though. – VvdL Dec 07 '22 at 16:25
  • 1
    @Vvdl thanks for the heads up. As you expected, fixing that didn't solve my issue. – Xar Dec 07 '22 at 16:31
  • 1
    Might be a long shot, but can it be possible the top answer to this very old question is your issue as well? https://stackoverflow.com/questions/15989529/unknown-column-in-field-list-but-column-does-exist – VvdL Dec 07 '22 at 16:39
  • 1
    maybe the productTeam in the database is saved with a space in the end, like 'productTeam '? – rszf Dec 07 '22 at 16:50
  • @rszf thanks for the input but I just ran this query `select * from ScasRepos where productTeam='X';` directly in MySQL and it worked, so I guess the name is written properly. – Xar Dec 07 '22 at 16:59
  • 1
    and if you execute the generated query directly? does it also fail? – rszf Dec 07 '22 at 17:12

0 Answers0