Database schema not updated using active record

When I add a new column (eg param) in the corresponding table from MySQL, the schema in yii is not updated (automatically).

I am using ActiveForm & ActiveRecord for getting input and saving the model respectively. In fact, although $model->param is recognizable and so I can set it from the form and then save the model, I can’t obtain the value with a batch mode ie $model->attributes doesn’t contain param, resulting $model->save() not to set/update param.

In same way, if I delete a column, then with a @$model-save() I get an Setting unknown property error for the deleted column.

In my web,console php files there is only one (same) cache component

‘cache’ => [

        'class' => 'yii\caching\FileCache',


while in db.php there are only basic keys (class,dsn,username,password,charset) and no schema cache.

I tried the googled yii cache/flush-schema and yii cache/flush-all from cmd to clear the cache but didn’t work. Again from the controller Yii::$app->db->schema->refresh() and Yii::$app->cache->flush() did not solve the problem.

Am I missing something? Why is it so difficult to get this work?

To use an attribute in mass-assignment (e.g. form submission), you need to declare it as “safe” in the model’s rules.

You are right! I totally forgot it because I thought there was a relation with the delete in database.

I also noticed that the problem with the removal db column only occurred with the User table.

Thank you very much for your remark. It was really helpful.