laravel批量插入报错:1292: Incorrect datetime value: '0000-00-00 00:00:00' for column 'TERM_DATE'

本文详细解析了在使用Laravel进行批量插入时遇到的数据库报错问题,并提供了三种有效的解决方案,包括手动添加时间字段、使用create或save方法及利用一对多的create方法。

一、背景

      在使用laravel的批量插入的时候,数据库报错,如标题所示。这就有点奇怪了,因为之前也是同样的表结构,但是并没有报错。

1、报错信息
在这里插入图片描述

2、关于laravel的批量插入可参考该博客

二、解决问题

      仔细看代码部分才发现,我使用的是model的insert方法。之前用create和save方法都是没问题的,那问题可能就出在这个insert上了。

这部分大家可以参考下博客:
https://blog.youkuaiyun.com/lanwithyu/article/details/74853268

      结论就是,用laravel的model自带的create和save方法都可以自动插入created_at和update_at时间。如果是用insert的话,不会自动插入时间的。

1、insert解决办法

自己手动在要添加的数组里面加上两个时间字段。也能达到批量插入且自带时间的效果

2、用create或者save方法

用这个方法的弊端就是,在批量插入中,需要在循环里面操作数据库了。实话实说,十分不推荐这种方法,实在是,太耗费性能了。

3、用一对多的create方法

这部分参考博客:
https://segmentfault.com/q/1010000004089790

      在model里面用hasMany()建立好一对多的关系,然后拼成数组,还是用create($data)的方式来创建。这里最好的方法就是这一种了,大家可以试试。

加油,各位!
end

数据导入失败: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO billing_data (yue_fen,doc_posting_date,bill_date,created_on,bill_doc,item_cat,bill_type,canceled,cancel_biling_no,created_by,payer,payer_nick_name,customer_device_id,payer_name_en,payer_name_zh,abbreviation_setting,payer_country,material,bu,process,process_category,process25d_fopop_detail,disclosed_first_item_book_version,service_billing_category,service_billing_content,prod_plant,ship_code,bump_plant,cp_plant,dps_plant,net_price,sales_qty,sales_qty_die_report,sales_unit,sales_pc_qty,wafer_qty,doc_currency,local_net_value_usd,bump_rev_usd,cp_rev_usd,dps_rev_usd,doi_rev_usd,ab2_rev_usd,ft_rev_usd,fop_ab1_rev_usd,foi_rev_usd,td_rev_usd,others_rev_usd,net_value_cny,bump_rev_cny,cp_rev_cny,dps_rev_cny,doi_rev_cny,ab2_rev_cny,ft_rev_cny,fop_ab1_rev_cny,foi_rev_cny,td_rev_cny,others_rev_cny,exchange_rate,acct_doc_no,bp_gl_account,cp_gl_account,dps_gl_account,tax_rate,tax_code,net_value,tax_amount,total_value_include_tax,good_die_count,gross_die_per_wafer,incoterms,sale_person,sale_person_name,po_number,sales_order,wafer_size,market,product_application,cust_lot_id,lot_id,wafer_lot,incoterms2,end_customer_code,batch,lot_type,bill_to,bill_to_country,sold_to,sold_to_country,ship_to,ship_to_country,reference_doc,reference_item,payment_term,vat_no,vat_date,fab_lot_type,wafer_id,customer_material,bp_probecard_or_mask,cp_probecard_or_mask,dps_probecard_or_mask,export_internal_doc_number,rmb_exchange_rate,ship_via,po_bp,po_cp,po_dps,po_ab2,bp_qty,bump_net_price,bump_sales_unit,cp_net_price,cp_qty,cp_sales_unit,category,dps_net_price,per_measure,dps_qty,dps_sales_unit,ab2_net_price,ab2_qty,ab2_sales_unit,cp_tester,front_prod_id,product_type,technology_id,service_type,wafer_source,tester_platform,tech_node,bill_doc_item,bill_cat,doc_cat,company,post_status,doc_fiscal_year,sales_order_item,end_customer_name,service_type_field,content,description,evidence,bp_area,device_structure,service_type_special_field,process_type,ft_net_price,ft_qty,ft_sales_unit,po_ft,po_doi,contains_interposer) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]; SQL state [HY000]; error code [1366]; Incorrect decimal value: '(5,684,461.00)' for column 'sales_qty' at row 1; nested exception is java.sql.BatchUpdateException: Incorrect decimal value: '(5,684,461.00)' for column 'sales_qty' at row 1(String), null, null, /sur-fico/fico/billingData/importExcel(String), null, java.lang.RuntimeException: 数据导入失败: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO billing_data (yue_fen,doc_posting_date,bill_date,created_on,bill_doc,item_cat,bill_type,canceled,cancel_biling_no,created_by,payer,payer_nick_name,customer_device_id,payer_name_en,payer_name_zh,abbreviation_setting,payer_country,material,bu,process,process_category,process25d_fopop_detail,disclosed_first_item_book_version,service_billing_category,service_billing_content,prod_plant,ship_code,bump_plant,cp_plant,dps_plant,net_price,sales_qty,sales_qty_die_report,sales_unit,sales_pc_qty,wafer_qty,doc_currency,local_net_value_usd,bump_rev_usd,cp_rev_usd,dps_rev_usd,doi_rev_usd,ab2_rev_usd,ft_rev_usd,fop_ab1_rev_usd,foi_rev_usd,td_rev_usd,others_rev_usd,net_value_cny,bump_rev_cny,cp_rev_cny,dps_rev_cny,doi_rev_cny,ab2_rev_cny,ft_rev_cny,fop_ab1_rev_cny,foi_rev_cny,td_rev_cny,others_rev_cny,exchange_rate,acct_doc_no,bp_gl_account,cp_gl_account,dps_gl_account,tax_rate,tax_code,net_value,tax_amount,total_value_include_tax,good_die_count,gross_die_per_wafer,incoterms,sale_person,sale_person_name,po_number,sales_order,wafer_size,market,product_application,cust_lot_id,lot_id,wafer_lot,incoterms2,end_customer_code,batch,lot_type,bill_to,bill_to_country,sold_to,sold_to_country,ship_to,ship_to_country,reference_doc,reference_item,payment_term,vat_no,vat_date,fab_lot_type,wafer_id,customer_material,bp_probecard_or_mask,cp_probecard_or_mask,dps_probecard_or_mask,export_internal_doc_number,rmb_exchange_rate,ship_via,po_bp,po_cp,po_dps,po_ab2,bp_qty,bump_net_price,bump_sales_unit,cp_net_price,cp_qty,cp_sales_unit,category,dps_net_price,per_measure,dps_qty,dps_sales_unit,ab2_net_price,ab2_qty,ab2_sales_unit,cp_tester,front_prod_id,product_type,technology_id,service_type,wafer_source,tester_platform,tech_node,bill_doc_item,bill_cat,doc_cat,company,post_status,doc_fiscal_year,sales_order_item,end_customer_name,service_type_field,content,description,evidence,bp_area,device_structure,service_type_special_field,process_type,ft_net_price,ft_qty,ft_sales_unit,po_ft,po_doi,contains_interposer) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]; SQL state [HY000]; error code [1366]; Incorrect decimal value: '(5,684,461.00)' for column 'sales_qty' at row 1; nested exception is java.sql.BatchUpdateException: Incorrect decimal value: '(5,684,461.00)' for column 'sales_qty' at row 1
最新发布
12-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

铁柱同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值