在Laravel应用程序中,mysql import将时间戳空值转换为0000-00-00 00:00:00 [英] In Laravel application, mysql import transforms timestamp null values to 0000-00-00 00:00:00

查看:339
本文介绍了在Laravel应用程序中,mysql import将时间戳空值转换为0000-00-00 00:00:00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel应用程序中,我有一个为softDeletes创建的MySQL时间戳字段 deleted_at ,默认值为NULL。如果值不为NULL,Eloquent将不会检索数据。当我导入CSV文件时,源文件的NULL值变为0000-00-00 00:00:00。

In Laravel application I have a MySQL timestamp field deleted_at which was created for softDeletes and the default value is NULL. If the value is not NULL the Eloquent will not retrive the data. When I import CSV file the NULL value from source file becomes 0000-00-00 00:00:00.

我读取 Mysql导入将时间戳空值转换为0000-00-00 00:00:00 和\N不适用于我。我有很多表,我需要定期导入,所以我真的需要解决这个问题。请帮忙。

I read Mysql import transforms timestamp null values to 0000-00-00 00:00:00 and \N does not worked for me. I have many tables which I need to import periodically, so I really need to fix this. Please help.

推荐答案

我想你应该看到你的 config / database.php 文件。此文件包含您可以设置严格模式 - 开/关的变量。

I think you should see your config/database.php file. This file contains the variable from where you can set the strict mode - On / Off.

Laravel现在可以启用/禁用mysql模式。有了这个新功能,Laravel现在有能力做三件事:禁用strict模式,返回到< = 5.6行为;启用严格模式,将其设置为5.7行为;

Laravel now gives you the power to enable / disable mysql modes. With this new feature, Laravel now has the ability to do three things: Disable "strict" mode, returning to the <= 5.6 behavior; enable "strict" mode, setting it to the 5.7 behavior; or customizing exactly which modes are enabled.

文件中的代码如下所示...

The code in your file goes like this...

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => true, // <----- This variable sets the strict mode.
        'engine' => null,
  ],

如果要禁用严格模式,请将此值设置为false否则使其为真以启用严格模式。
希望这有助于你解决你的问题。

set this value to false if you want to disable the strict mode else make it true to enable the strict mode. Hope this help you to solve your problem.

这篇关于在Laravel应用程序中,mysql import将时间戳空值转换为0000-00-00 00:00:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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