Yii Framework Forum: update model from db - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

update model from db Rate Topic: -----

#1 User is offline   zipzap 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 314
  • Joined: 13-January 12

Posted 17 March 2012 - 02:30 PM

I added an atribute to db.How to update model with this new attribute?
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 18 March 2012 - 04:52 AM

This is what I would do

  • delete db schema chaches in protected/runtime/cache
  • run model generator of gii
  • preview the modified model code and cut and paste what should be changed


The 3rd process can be different. You may totally overwrite the existing code if you don't mind loosing all the changes that you have made before.

Or, if the changes are trivial, you may manually edit the code, not using gii.

Any way, you should clear the db schema cache when you have made changes to the db schema.
0

#3 User is offline   zipzap 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 314
  • Joined: 13-January 12

Posted 18 March 2012 - 06:08 AM

View Postsoftark, on 18 March 2012 - 04:52 AM, said:

This is what I would do

  • delete db schema chaches in protected/runtime/cache
  • run model generator of gii
  • preview the modified model code and cut and paste what should be changed


The 3rd process can be different. You may totally overwrite the existing code if you don't mind loosing all the changes that you have made before.

Or, if the changes are trivial, you may manually edit the code, not using gii.

Any way, you should clear the db schema cache when you have made changes to the db schema.


you delete the code inside modelcode.php?
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 18 March 2012 - 06:42 AM

View Postzipzap, on 18 March 2012 - 06:08 AM, said:

you delete the code inside modelcode.php?

I mean, you can run gii to update your model codes in your "protected/models" directory.
I don't delete any code. I just delete "db schema caches" in "protected/runtime/cache".
You must not touch any codes under the "framework" directory.
0

#5 User is offline   zipzap 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 314
  • Joined: 13-January 12

Posted 18 March 2012 - 06:47 AM

but i dont have that cache directory under protected/runtime. just gii-1.1.10 and the file application.log
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,005
  • Joined: 16-February 11
  • Location:Japan

Posted 18 March 2012 - 07:22 AM

Oh, I'm sorry.
If you haven't configured the app to enable the db schema cache, then you don't have to worry about it.
But I recommend you to read the following.
http://www.yiiframew...hing-techniques
http://www.yiiframew...Duration-detail
0

#7 User is offline   iPit 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-July 12
  • Location:Oviedo, Spain

Posted 16 August 2012 - 04:42 AM

View Postsoftark, on 18 March 2012 - 04:52 AM, said:


  • delete db schema chaches in protected/runtime/cache




On version 1.1.10 is not necessary delete db schema caches -in fact, my FTP doesn't let me delete those files because I'm not authorized-. Yii updates the db schema caches.

I changed my DB and in Gii I updated the model but without rewrite my model's file, because I have made lots of changes on model's file and the change in DB was small, so added this little change in my model's file's code. All went fine doing in this way.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users