【问题标题】:How to insert into Postgres dateTimeTz with Laravel and Carbon?如何使用 Laravel 和 Carbon 插入 Postgres dateTimeTz?
【发布时间】:2019-08-19 08:16:58
【问题描述】:

我想使用带有时区数据类型的 Postgres 时间戳记。

我的迁移有这一行:

$table->dateTimeTz('local_timestamp');

我尝试这样播种:

$note->local_timestamp = Carbon::now();

我在播种时也尝试过这样格式化:

$note->local_timestamp = Carbon::now()->format('Y-m-d H:i:sO');

我这样检索我的种子数据:

$data = Note::where('owner', $owner)->get();

我在 Carbon 错误中收到 InvalidArgumentException“数据丢失”,显示如下:

at Carbon::rawCreateFromFormat('Y-m-d H:i:sO', '2019-03-28 14:02:42', null)

我已经尝试在我的模型中包含这条线,因为我已经看到它建议作为其他类似问题的答案:

protected $dateFormat = 'Y-m-d H:i:sO';

【问题讨论】:

    标签: laravel postgresql-9.1 php-carbon


    【解决方案1】:

    从模型中删除日期格式解决了这个问题。

    这个答案很有用-Laravel Carbon Data Missing

    我根据这个答案更改了日期格式 - timestampTz fields in Laravel - 它处理 timestamptz 数据类型(不是 datetimetz)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      • 2019-05-04
      • 1970-01-01
      • 2017-08-10
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      相关资源
      最近更新 更多