Yii2 Add timestamp into model

212 Views Asked by At

I need to insert a timestamp element in the model. How can I do it, below I enter my code. I tried to do this but it gives me an error. I post it below. How can I do, someone would be able to help me

Exception: Call to undefined function timestamps()
<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%reporting}}`.
 */
class m220510_213949_create_reporting_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%reporting}}', [
            'id' => $this->primaryKey(),
            'id_user' => $this->integer()->notNull(),
            'link' => $this->text()->notNull()->unique(),
            'note' => $this->text()->notNull(),
            'state' => "ENUM('Sent','In processing','Analyzed','Error') NOT NULL",
            'sent_date_analysis' => $this->timestamp(),
            'start_date_analysis' => $this->timestamp(),
            'end_date_analysis' => $this->timestamp(),
        ]);

}
1

There are 1 best solutions below

0
WorraccCdP On

I succeeded, basically it couldn't be added without a default value, and so I entered NULL and continued like this:

        'sent_date_analysis' => $this->timestamp()->defaultValue(NULL),
        'start_date_analysis' => $this->timestamp()->defaultValue(NULL),
        'end_date_analysis' => $this->timestamp()->defaultValue(NULL),