0
votes

in my yii2 advanced template, i get the exception SQLSTATE[22003] of the database.

with this error message:

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 user (username, email, password_hash, auth_key, status, created_at, updated_at) VALUES ('test', '[email protected]', 'someval', 'someval', 10, NOW(), NOW())

i checked the fields that cause this exception (i've assumed that are the date fields created_at and updated_at) and they're both int(20).

in the model i've timestamp behavior:

/**
 * @inheritdoc
 */
public function behaviors()
{
    return [
        [
            'class' => TimestampBehavior::className(),
            'attributes' => [
                ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
            ],
            'value' => new \yii\db\Expression('NOW()')
        ],
    ];
}

I really don't know what cause this error. This is the standard registration functionality inserted in the yii2 advanced template.

Thanks in advance for the help

1

1 Answers

1
votes

value of NOW() is not integer its something like 2016-06-13 13:36:28 which is not in integer, so change your table as timestamp,datetime or varchar

ALTER TABLE `user` CHANGE `created_at` `created_at` TIMESTAMP NOT NULL;
ALTER TABLE `user` CHANGE `updated_at` `updated_at` TIMESTAMP NOT NULL;

And use quote around NOW()