为什么CakePHP中的查询结果中没有出现新的表列?

时间:2022-11-11 21:20:09

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.

我已经在我的表属性中添加了一个新列,它已经有(id,form_id(外键),类型,标签,大小,序列号,instr)其中instr是我添加的新列。

My application is in CakePHP and MySQL.

我的应用程序在CakePHP和MySQL中。

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

我已经使用以下代码插入表中的属性但是单独的字段instr没有插入。

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..

请建议我..

2 个解决方案

#1


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

有关表结构的信息可能已缓存。删除“app / tmp / cache / models”的内容并再次尝试。

#2


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.

请注意,在开发中,app / config / core.php中的调试级别通常设置为> 1.这意味着您永远不应该遇到开发中的问题,因为Cake不会缓存。但是,在生产中,core.php中的debug设置为0,从而导致cake开始缓存。

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.

为了补充一点,我删除了app / tmp / cache / models中的缓存文件,就像我在生产的CakePHP应用程序中指定的dhofstet一样,查找查询仍然没有抓住我的新列。

--

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.

除了清除模型缓存文件之外,我还在生产站点上将调试级别设置为2并进行页面刷新,然后将其设置为0并使其再次运行。我知道这是一个丑陋的方法,但是当没有其他方法可行时,它为我修复了它。

#1


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

有关表结构的信息可能已缓存。删除“app / tmp / cache / models”的内容并再次尝试。

#2


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.

请注意,在开发中,app / config / core.php中的调试级别通常设置为> 1.这意味着您永远不应该遇到开发中的问题,因为Cake不会缓存。但是,在生产中,core.php中的debug设置为0,从而导致cake开始缓存。

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.

为了补充一点,我删除了app / tmp / cache / models中的缓存文件,就像我在生产的CakePHP应用程序中指定的dhofstet一样,查找查询仍然没有抓住我的新列。

--

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.

除了清除模型缓存文件之外,我还在生产站点上将调试级别设置为2并进行页面刷新,然后将其设置为0并使其再次运行。我知道这是一个丑陋的方法,但是当没有其他方法可行时,它为我修复了它。