Why doesn't a new table column show up in the query results in CakePHP?

Go To StackoverFlow.com

5

I have added a new column to my table Attributes which already has (id , form_id(foreign key),type,label,size,sequence no,instr) where instr is the new column i have added.

My application is in CakePHP and MySQL.

I have used the following code to insert into the table Attributes But the field instr alone not inserted.

function saveFieldname($data)//from untitledfieldname
{   
    $this->data['Attribute']['form_id'] = $this->find(  'all', array(
                                                        'fields' => array('Form.id'),
                                                        'order' => 'Form.id DESC'
                                                     ));

    $this->data['Attribute']['form_id'] = $this->data['Attribute']['form_id'][0]['Form']['id'];

    $this->data['Attribute']['label'] = 'Label';
    $this->data['Attribute']['size'] ='50';
    $this->data['Attribute']['instr'] ='Fill';

    $this->data['Attribute']['type'] = $data['Attribute']['type'];
    $this->data['Attribute']['sequence_no'] = $data['Attribute']['sequence_no'];

    $this->Attribute->save($this->data);
}

Please suggest me..

2009-06-16 09:12
by useranon


7

The information about the structure of your table is probably cached. Remove the content of "app/tmp/cache/models" and try it again.

2009-06-16 09:34
by dhofstet
Ya Now i have removed the files in /cache/Models folder now its done. Thank u - useranon 2009-06-16 09:36
Thank you so much, I was beating my head against the wall about thi - Glenn Slaven 2009-08-24 11:41
where can we do this on cakephp 2.4.3 @dhofstet - Leah 2014-07-30 02:53
@LeahKwon it's the same folder on CakePHP 2.4. - dhofstet 2014-07-30 06:07


1

Note that in development the debug level in app/config/core.php is usually set to > 1. This means you should never run into the issue in development because Cake will not cache. However, in production, debug is set to 0 in core.php, thus causing cake to start caching.

To add to that, I had removed the cache files in app/tmp/cache/models as dhofstet specified on my production CakePHP app and the find queries were still not grabbing my new column.

--

As well as clearing the model cache files, I set the debug level to 2 on my production site and did page refresh then set it back to 0 and it got it working again. I know this is an ugly approach, but it fixed it for me when no other methods were working.

2014-12-04 18:28
by karns
No....!!!! this is not work for me - satyawan 2016-10-22 20:07