Mysql virtual column

I am trying to use mysql json column index feature.

ALTER TABLE jobs ADD eta varchar(50) GENERATED ALWAYS AS (JSON_EXTRACT(shipping_info, '$.eta')) VIRTUAL

but when I save jobs with model, it gives me the error,

SQLSTATE[HY000]: General error: 3105 The value specified for generated column 'eta' in table 'jobs' is not allowed.

Does anyone have similar problem and get it solved?

Thanks

You're using ORM or Query builder?

I believe you have to go to PDO raw for such feature.



6.3k

I am using default phalcon model, which is using PDO I guess, like

$job = new Job();
$job->shipping_info = $shipping_info;
$job->save();

I just realised it is because of it is a virtual column and I can not save the data, and I have to skip it, so the problem is solve by telling the model to skip this virtual column,

public function initialize(){

        $this->skipAttributes([
            'eta',
        ]);
}

You're using ORM or Query builder?

I believe you have to go to PDO raw for such feature.