Datetime Field Type default_value "now" shows invalid value

sumentuten - 2 months ago

I can't seem to set a default value for the datetime fieldtype. Here is the config I set for the fieldtype:

'date_received' => [ 'type' => 'anomaly.field_type.datetime', 'config' => [ 'default_value' => "now", 'mode' => 'date', ], ], ]

shows error:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'date_received' (SQL: alter table laundrylab_laundrylab_orders add date_received date not null default 'now')

Answer

- 2 months ago

This should probably be accounted for in the schema builder for this FT but.. I would not put the defualt value there but instead where you define the fields - override the default value (from null) there instead. This way it's not trying to modify the column in that way.

I've made an issue to track the issue as well: https://github.com/pyrocms/pyrocms/issues/4284

ryanthompson - 2 months ago

This should probably be accounted for in the schema builder for this FT but.. I would not put the defualt value there but instead where you define the fields - override the default value (from null) there instead. This way it's not trying to modify the column in that way.

I've made an issue to track the issue as well: https://github.com/pyrocms/pyrocms/issues/4284

sumentuten - 2 months ago

Got it. Will do it that way, instead. Thanks!