2013-06-01 47 views
1

我想用zend框架在表中插入數據。我有以下表結構Zend_Db_Table_Exception:表必須有一個主鍵,但沒有找到

enter image description here

當我嘗試在該表中,我發現錯誤

Zend_Db_Table_Exception: A table must have a primary key, but none was found 

插入數據,當我在我的表,請指定protected $_primary ='id'我發現錯誤

Primary key column(s) (id) are not columns in this table() 

我已經刪除了表並從頭創建,但都是徒勞的。自數小時以來,我一直試圖解決這個問題,但沒有得到任何解決方案。

我的模型看起來像

protected $_name = "affiliate_specialities_banners"; 
//protected $_primary = 'id'; 
protected $_adapter = null; 

public function init() { 
    $this->_adapter = $this->getAdapter(); 
} 

public function addData($data) { 
    try { 

     $id = $this->insert($data); 
    } catch (Zend_Db_Adapter_Exception $e) { 

     die($e->getMessage()); 
    } 
    return $id; 
} 

請什麼建議......

回答

2

我想你使用的表元數據高速緩存,所以ZF是使用舊版本的猜測不包含主鍵的表結構。刪除緩存文件應該解決這個問題。或者,確保它連接到您在phpMyAdmin中查看的數據庫。

+0

那麼我正在開發一個已經開發的系統。我試圖找出哪裏緩存正在存儲,但無法找到。 :-(我已經刪除了www目錄下的所有tmp文件夾,但沒有任何事情發生。:-( –

+0

搜索'setDefaultMetadataCache'的源代碼,這可能會幫助您查找是否以及在何處使用緩存 –

相關問題