我想使用zend框架在表中插入数据。我有以下表结构
当我尝试在此表中插入数据时,我发现错误
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;
}
请提出任何建议......
答案 0 :(得分:2)
我猜您正在使用表元数据缓存,因此ZF使用的表格结构的旧版本不包含主键。删除缓存文件应该解决这个问题。或者,请确保它已连接到您在phpMyAdmin中查看的数据库。