Adding new columns to model

Is there anything that I need to add to my model files when I create a new column in my database because if I just add it in the database and try to access it in yii, it never works. Basically I can never save to that field but yet if I recreate the model than I can save.

Thank you

Look at the code in your corresponding model class.

And it should become clearer what you need to do. :)

But thats the thing, the field I added did not need rules, relations and did not need to be searchable. I added it to a form but when I went to save it didn’t save anything. I then tried assigning a direct value to it and then saving and yet again, nothing went into the database. But if I recreate the model, then saving works for that field. What causes this?

If you don’t want or need any validation rules, just add it to the array of safe attributes. :)

Hi Everyone,

I just want to contribute this which took me 8 hours yesterday to figure out.

if you are getting

model.attribute undefine.

You need 3 things. That mean that the schema cache is not reflecting your new column

  1. Add a validation rule in rules

  2. Add label (for commenting)

  3. [size="5"]Clear the cache!!! Yii:: app () ->cache->flush() [/size]

It should work, try cleaning up cache as auzadventure told you…