Adding a new table column to an existing model

I’m struggling to add a new table column to an existing app and am obviously missing something simple here.

I’ve added it to the model

  • @property string $InitialRequest

[[…, ‘InitialRequest’], ‘safe’]

‘InitialRequest’ => Yii::t(‘app’, ‘Initial Client Request’),

yet, I still get

Exception (Unknown Property) ‘yii\base\UnknownPropertyException’ with message ‘Setting unknown property: backend\models\Projects::InitialRequest’

What have I overlooked?

Do you have a Search Model related to the model in question? When I add an attribute I make sure it’s in the database first, then model, then search model.

I did indeed add it to the safe rule in the search model.

I don’t get it.
I renamed the file, generated a new model using gii, deleted the newly generated file, renamed the file back and it works?! I have no clue what is going on, some type of caching or something.

this could have been a schema cache issue. Next time just clear all caches first.

Yes it happens with schema cache, Go to gii and generate same model again, no need to save the new files. :slight_smile:

How does one clear the cache? I clear my browser cache and it did nothing, so I’m assuming you are referring to some yii2 cache, how do I flush that?


There is also a console command that ships with Yii2 that allows you to clear cache from the cli.

if you run php yii cache/flush-all you’ll be able to clear the cache from the cli.

Clear your cache folder under /runtime/cache/ . This worked for me before.
Also, make sure the column exists in the table in question.