As a workaround, you could use nullable timestamps, in which case MySql will not use CURRENT_TIMESTAMP as default.
Multiple timestamps in one table
I have just read: https://github.com/laravel/framework/issues/11518 and have been left more confused than I began. It seems there are issues with certain versions of MySQL and Laravel with regards to default values on timestamp fields.
I have a tasks table as follows:
Schema::create('tasks', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('content');
$table->datetime('deadline');
$table->datetime('reminder');
$table->integer('user_id')->index();
$table->timestamps();
});
What are the pros and cons of using datetime vs timestamp for the 'deadline' and 'reminder' fields? In order to use Laravel's built-in Carbon handling (by adding these fields to $dates) I understand they need to be timestamps. But setting these as timestamps causes unexpected behaviour in that it specifies for the first field (i.e. deadline) CURRENT_TIMESTAMP on update and also a default CURRENT_TIMESTAMP which is undesired behaviour.
My workaround of the issues in the link above are currently to stick to using datetime and initialising new Carbon objects in my Attribute methods (i.e. not being able to use $dates for my own fields for now).
Yes, or else the very first non-null field will be set to use CURRENT_TIMESTAMP as default.
Edit: BTW.
nullableTimestamps() are only for default fields created_at, updated_at. for custom fields use timestamp()->nullable();
Please or to participate in this conversation.