Home >Database >Mysql Tutorial >How to Fix MySQL\'s Only_full_group_by Error in Laravel Eloquent?

How to Fix MySQL\'s Only_full_group_by Error in Laravel Eloquent?

DDD
DDDOriginal
2024-11-21 04:18:11825browse

How to Fix MySQL's Only_full_group_by Error in Laravel Eloquent?

Resolving MySQL's Only-Full-Group-By Problem in Laravel Eloquent

When executing Laravel Eloquent queries, you may encounter the error "Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column..." indicating that MySQL's strict mode (sql_mode=only_full_group_by) is enabled.

To resolve this issue, you can disable MySQL's strict mode in your database connection settings:

'connections' => [
    'mysql' => [
        // Behave like MySQL 5.6
        'strict' => false,

        // Behave like MySQL 5.7
        'strict' => true,
    ]
]

This will allow you to execute queries without the need to explicitly aggregate non-grouped columns. Additionally, you can explore other configuration settings mentioned in Matt Stauffer's blog post for further customization.

The above is the detailed content of How to Fix MySQL's Only_full_group_by Error in Laravel Eloquent?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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