4

A theoretical issue.

Laravel eloquent migration $table->timestamps(); made up two fields. created_at and updated_at. Both timestamp type. Default value 0000-0....

MySQL tables can be created as follows.

created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,

updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

Data editing date (updated_at) will be updated even not using eloquent (DB::raw, DB::table insert, update, etc).

On the other DB systems are never moved. Therefore, relocation benefits are not important. Can be adapted directly to mysql.

question No. 1

As I understand, using eloquent $var->save() mysql can updated_at rewritten twice?

question No. 2

Is ir whorth it to put CURRENT_TIMESTAMP in mysql tables? Or better for all RAW insert update queries fields set NEW() in code?

Andris Briedis
  • 434
  • 1
  • 3
  • 13

0 Answers0