0

In yii2 migration file i had create two columns

'updated_at' => $this->integer()->defaultValue('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
'created_at' => $this->integer()->defaultValue('CURRENT_TIMESTAMP')

But this is working in MYSQL, and it will not working in PostgreSQL?

How to create column with updating timestamp column when I update the row, and set default timestamp when I create the row.

1 Answers1

1

You can use yii\behaviors\TimestampBehavior if you want solution that wouldn't be dependent on used DBMS.

Otherwise you have to use trigger to set the current timestamp on update. See this question for more info Update timestamp when row is updated in PostgreSQL

Michal Hynčica
  • 5,038
  • 1
  • 12
  • 24