Laravel数据库严格模式 [英] Laravel Database Strict Mode

查看:1074
本文介绍了Laravel数据库严格模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我毫不奇怪,请帮帮我.

I'm little wonder please help me out.

我的查询是:-Invoice::join('orders', 'orders.invoice_id', '=', 'invoices.id')->groupBy('invoices.id')->get();

然后我遇到一个错误:语法错误或访问冲突:1055'invoices.reference_number'不在GROUP BY中

Then I have got an error: Syntax error or access violation: 1055 'invoices.reference_number' isn't in GROUP BY

当我根据错误更新查询时,查询为:-

When I updated my query according to error then the query is:-

$invoices = Invoice::join('orders', 'orders.invoice_id', '=', 'invoices.id')->groupBy('invoices.id','invoices.reference_number','invoices.customer_address_id','invoices.country_id','invoices.paid_at','invoices.due_date','invoices.created_at','invoices.updated_at','invoices.deleted_at','orders.id','orders.currency_id','orders.user_id','orders.customer_id','orders.created_at','invoices.updated_at')->get();

现在查询有效,但在那种情况下,我不能使用select(),它返回在groupBy()

Now query working but in that case, I can't use select(), It returns columns who is in the groupBy()

所以我做了google,然后发现如果我关闭数据库严格模式,那么它将正常工作,然后又能正常工作,但是我不希望严格模式关闭.

So I did google then found if I do database strict mode off then it will work and then I did and it's working good, But I don't want strict mode turned off.

我还对数据库模式进行了研究 https://dev.mysql.com/doc/refman/5.5/zh-CN/faqs-sql-modes.html

Also, i did the study about database modes https://dev.mysql.com/doc/refman/5.5/en/faqs-sql-modes.html https://dev.mysql.com/doc/refman/5.5/en/sql-mode.html

然后我找到了查询:-SELECT @@GLOBAL.sql_mode; SELECT @@SESSION.sql_mode;

Then I found query:- SELECT @@GLOBAL.sql_mode; SELECT @@SESSION.sql_mode;

但结果为空白

如果我在数据库中进行操作-select * from invoices inner join orders on orders.invoice_id = invoices.id where invoices.deleted_at is null group by invoices.id

If I do in the database - select * from invoices inner join orders on orders.invoice_id = invoices.id where invoices.deleted_at is null group by invoices.id

然后它可以正常工作,意味着没有通过mySQL进行任何模式验证,它已经配置了Laravel端

Then it's working fine means no mode validations trough mySQL it has configured side of Laravel

此外,我还没有在laravel文档中找到相关的数据库模式

Also, i haven't found related database modes in laravel documentation

因此,如果我做错了什么,请帮助我.

So help me out if I did wrong something.

我还想知道在laravel中启用了谁的数据库严格模式验证,因为我想知道什么严格验证会给我一个错误.

And i also want to know who's database strict mode validation is enabled in laravel because I have wonder what strict validation giving me an error.

推荐答案

config/database.php

'strict' => true,

收件人

'strict' => false,

这篇关于Laravel数据库严格模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆