0
votes

In my migration I have two extra timestamp

$table->timestamp('starts_at');

$table->timestamp('ends_at');

I dont want them to be nullable,problem is,when i run php artisan migrate I returns

Syntax error or access violation: 1067 Invalid default value for 'ends_at'

I have $table->timestamps() at the bottom. How can I have my custom timestamp column/s and not nullable

A way around is to simply put nullable() at the end but its not a fix.using laravel 5.7

2
Do you already have records in the table? If so, you either need to make these timestamps nullable, set a default, or empty the table and then migrate. - Stefan Teunissen
i have no data in that table,its a fresh migration after running php artisan make:migration my_migration_name - user7116461
Are you okay with using "dateTime" instead of "timestamp"? - Stefan Teunissen

2 Answers

0
votes

I hope you are looking for datetime data type for that field. Try the below code.

$table->datetime('starts_at');
$table->datetime('ends_at');

if you want to make this field as nullable try below.

$table->dateTime('starts_at')->nullable();
$table->dateTime('ends_at')->nullable();
-2
votes

You should try this:

 $table->timestamp('starts_at');

 $table->timestamp('ends_at')->default('0000-00-00 00:00:00');