Reputation:
I have Generated CRUD with Gii, but my migrations don't work as expected to.
'id' => $this->primaryKey(),
'student' => $this->string(255)->notNull(),
'diploma_teacher' => $this->string(255)->notNull(),
'type_of_work' => $this->string(255)->notNull(),
'student_classification' => $this->string(255)->notNull(),
'title' => $this->string(255)->notNull(),
'created_at' => $this->dateTime()->notNull(),
'updated_at' => $this->dateTime()->notNull(),
When creating new Diploma Work the field for created_at and updated_at
0000-00-00 00:00:00
0000-00-00 00:00:00
Upvotes: 0
Views: 187
Reputation: 487
I would suggest you declare the create_at
and update_at
as follow,
'create_at' => $this->dateTime()->notNull()->defaultExpression('now()'),
'update_at' => $this->dateTime()->notNull()->defaultExpression('now()')->append('ON UPDATE CURRENT_TIMESTAMP')
Upvotes: 1
Reputation: 133360
You should add the default value expression
'created' => $this->dateTime()->notNull()->defaultExpression('now()')
Upvotes: 0