[Solved] SQLSTATE[HY000]: General error: 1 no such function: FIELD (SQL: select * from … by FIELD(id, 1) limit 10000 offset 0)

2023/05/20 17:34

Error

When writing a test code using sqlite’s in-memory function with Laravel, I got the following sql syntax error.

SQLSTATE[HY000]: General error: 1 no such function: FIELD (SQL: select * from … by FIELD(id, 1) limit 10000 offset 0)

Solution

if (env(‘DB_CONNECTION’) === ‘mysql’) { $this->query->orderByRaw(‘FIELD(‘ ‘)’); }

Leave a Reply

Back to top