G
G
Greg Popov2016-06-10 02:10:52
MySQL
Greg Popov, 2016-06-10 02:10:52

Why is TimestampBehavior in Yii2 throwing an error?

// behavior:
'timestamp' => [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at',
                'value' => new Expression('NOW()'),
            ],

Mistake:
SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'created_at' at row 1
The SQL being executed was: INSERT INTO `category` (`parent_id`, `title`, `mk`, `md `, `visibility`, `created_at`, `updated_at`, `created_id`, `updated_id`, `slug`) VALUES (NULL, 'Stepper motor controllers', '', '', 1, NOW(), NOW( ), 1, 1, 'kontrollery_sagovyh_dvigatelej')

Date fields
int(11)
,
did everything according to the manual, out of sync in one day, plus does not add an update date if I just write
return [

            TimestampBehavior::className(),
            // ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Артем Сошников, 2016-06-10
@Gregpopov

Попробуйте добавить в поведение

'value' => new Expression('UNIX_TIMESTAMP(NOW())'),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question