Yeah, that 'Y-m-d H:i:s.u' data format was there because I was testing an override in the model file:
protected $dateFormat = 'Y-m-d H:i:s.u';
I also tried it without the override and with this from that Laracasts link above:
protected $dateFormat = 'Y-m-d H:i:s.u0';
Same problem. The Postgresql data type on those date fields is "timestamp(0) with time zone" so it shouldn't be storing fractional seconds.
I should have mentioned that this is only happening on updates to existing database records, not on inserts. For instance I created this record with no problems:
hrl2=# select * from urls where id=1304;
id | link_text | link_url | node_id | group | site | location | is_published | created_by | link_weight | created_at | updated_at | ref_section_id | lang | media | description | video_id
------+--------------------+-----------------------+---------+-------+------+----------+--------------+------------+-------------+------------------------+------------------------+----------------+------+---------+--------------------------+----------
1304 | Laracasts web site | https://laracasts.com | 6 | all | nyc | related | t | admin | 0 | 2020-01-25 12:37:24-05 | 2020-01-25 12:37:24-05 | | en | website | Test test test test test |
(1 row)
hrl2=# \gx
-[ RECORD 1 ]--+-------------------------
id | 1304
link_text | Laracasts web site
link_url | https://laracasts.com
node_id | 6
group | all
site | nyc
location | related
is_published | t
created_by | admin
link_weight | 0
created_at | 2020-01-25 12:37:24-05
updated_at | 2020-01-25 12:37:24-05
ref_section_id |
lang | en
media | website
description | Test test test test test
video_id |
But when I try to update it I get the error.
UPDATE: I just discovered this. If I null out that updated_at column in the database, and have that first $dataFormat pattern ('Y-m-d H:i:s.u') in the model and then update the record from Laravel it works fine. You can update that row over and over again and there's no issue.
update urls set updated_at = null where id=330;
What's strange is that the timestamp column looks the same in psql. But that doesn't mean that it's not different internally.
So this does seem to indicate a database issue. The web server is running on Ubuntu 18.04. When I upgraded it from 16.04 this past summer it updated Postgres to v10 while the existing database records were created on v8 and v9. That seemed to work fine with Laravel 5.4. But with the upgrade to 5.8, it broke Carbon on those legacy database columns.
Since the updated_at columns aren't critical to the application I think I can just get away with adding that $dateFormat to the model files and then update all the updated_at columns in the table to null.