Home > Backend Development > PHP Tutorial > How to Fix Laravel's 'Syntax error or access violation: 1055' Error When Using WhereIn and GroupBy?

How to Fix Laravel's 'Syntax error or access violation: 1055' Error When Using WhereIn and GroupBy?

Barbara Streisand
Release: 2024-12-09 09:51:07
Original
383 people have browsed it

How to Fix Laravel's

Troubleshooting "Syntax error or access violation: 1055" in Laravel

When using WhereIn and GroupBy in the same query, you may encounter an error such as "SQLSTATE[42000]: Syntax error or access violation: 1055". This indicates a violation of SQL's requirement to have all non-aggregated columns included in the GROUP BY clause.

To resolve this issue, there are two options.

Disable Strict Mode

In your config/database.php file, under the 'mysql' array, set 'strict' to false. This will disable all strict mode settings.

Specify Allowed Strict Modes

Alternatively, you can leave 'strict' as true and add specific modes to the 'modes' option. To allow grouping by one column without including it in the GROUP BY clause, comment out the 'ONLY_FULL_GROUP_BY' mode.

'mysql' => [
    ...

    'strict' => true,
    'modes' => [
        // 'ONLY_FULL_GROUP_BY', // Disable this to allow grouping by one column
        'STRICT_TRANS_TABLES',
        'NO_ZERO_IN_DATE',
        'NO_ZERO_DATE',
        'ERROR_FOR_DIVISION_BY_ZERO',
        'NO_AUTO_CREATE_USER',
        'NO_ENGINE_SUBSTITUTION'
    ],
]
Copy after login

You can continue to use WhereIn and GroupBy without encountering the "1055" error.

Note: It's recommended to use strict mode for security and data integrity reasons. However, you may need to disable it temporarily for queries that require grouping by non-aggregated columns.

The above is the detailed content of How to Fix Laravel's 'Syntax error or access violation: 1055' Error When Using WhereIn and GroupBy?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template