我最近刚从MySQL迁移到PostgreSQL。我注意到我一直收到这个错误
InvalidArgumentException in Carbon.php line 425:
Trailing data
然后,我在我的应用程序中对Carbon::
进行了全局搜索。我在15个文件中找到了47个匹配项。
如何在不修改所有这些文件的情况下修复此错误?
我dd()我的对象这是我得到的
Capture {#412 ▼
#table: "captures"
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:6 [▼
"id" => 65
"type" => "cpe"
"cpe_mac" => "000D6721A5EE"
"device_mac" => null
"created_at" => "2016-05-03 11:20:10-04"
"updated_at" => "2016-05-03 11:20:10-04"
]
....
这正是你的想法。这里的问题是timestamp
中的PostgreSQL
列实际上期望一种不同的时间戳格式,其中包括最后的miliseconds
。 'Y-m-d H:i:s.u'
与Carbon的默认格式相反,MySQL的时间戳列只是'Y-m-d H:i:s
。为了解决这个问题,请告诉PostgreSQL您不希望将时区存储为timestamp
列中字符串的一部分:
ALTER TABLE {tablename} ALTER updated_at SET DATA TYPE timestamp(0) without time zone;
您需要对所有具有时间戳的表和所有列执行此操作。
意识到这是一个老帖子,但我通过创建一个全局范围解决了这个问题。见:https://laravel.com/docs/5.6/eloquent#global-scopes
然后我做了:
$ builder-> addSelect(['select','cols','here',to_char(created_at,'YYYY-MM-DD HH24:MI:SS')as created_at“];
这意味着与Laravel合适。因为我只是从这个DB读取,所以不需要考虑更新时间戳。