1

I insert the field like this:

$table->timestamp('added_on')->default('CURRENT_TIMESTAMP'),

but in SQLite the default value is 'CURRENT_TIMESTAMP' and it does not work (does not replace with the current date). It is necessary that the field had the value CURRENT_TIMESTAMP, then it will work. Can this be done in Laravel?

MyNick
  • 131
  • 1
  • 7
  • Why not use $table->timestamps()? then you will have 2 fields: created_at and updated_at that laravel will handle automatically. And then if you absolutely want the field to be named added_on add an accesor. – Indra Feb 05 '19 at 09:54
  • thanks, next time i will use this way – MyNick Feb 05 '19 at 12:00

1 Answers1

3

Try wrapping it in DB::raw so it's executed as a SQL function:

$table->timestamp('added_on')->default(\DB::raw('CURRENT_TIMESTAMP'));

Or you can use ->useCurrent(); Laravel helper like this :

$table->timestamp('added_on')->useCurrent();
Maraboc
  • 10,550
  • 3
  • 37
  • 48
Marcin
  • 1,488
  • 1
  • 13
  • 27