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 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.