0

I have created Model called ExpertQuestion using Gii

After that i added column in table from which i generated Table.

So, my question is how to add column in my ExpertQuestion Model to access it.

Error:

Unknown Property – yii\base\UnknownPropertyException

Setting unknown property: app\models\ExpertQuestion::is_deleted

Yasin Patel
  • 5,624
  • 8
  • 31
  • 53

5 Answers5

1

Re run Gii for that table and copy and paste the missing information over into your model.

Alternatively if you have no additional code in the model just overwrite the whole model

Or you can use something like Giiant where you have base models that your actual model inherit from, this means you just re run the base model when changes in your DB occur and you don't overwrite any code in your actual model that implements this base model.

Jonnny
  • 4,939
  • 11
  • 63
  • 93
1

Let's consider the new column name as newCol in your model

update rule function

public function rules()
{   
   return [.....

      [['newCol'], 'string', 'max' => 30],

      ];   
}

Then add labels

public function attributeLabels()
{
        return [...

         'newCol' => Yii::t('app', 'L Name'),

       ];    
}

Now open Search model and update

public function search($params)
{
    ....

    $query->andFilterWhere(['like', 'newCol ', $this->newCol ])

    ....

    return $dataProvider;    
}
Rick Smith
  • 9,031
  • 15
  • 81
  • 85
sujoi
  • 95
  • 1
  • 1
0

Edit model file and write new field name in rules.

Ex: new field is is_deleted(string) then write new rule for this field.

[['is_deleted'], 'string'],
Yasin Patel
  • 5,624
  • 8
  • 31
  • 53
Arshad Shaikh
  • 564
  • 1
  • 3
  • 13
0

Аgain generate the model in Gii, click on the diff button, and copy and paste to your Model that relates to your new field.

screen diff button

Vitaly
  • 1,261
  • 2
  • 10
  • 20
0

This is related at the way yii1 cache the models

If you don't need tu re run Gii for a new generation of model ..

you can simply .. delete the runtime directory of your app

   yourApp/runtime  
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107