3

I am following the: http://framework.zend.com/manual/en/learning.quickstart.create-model.html.

Keep hitting wall after wall of issues. My current one is the following error:

An error occurred

Application error

Exception information:

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

Stack trace:

#0 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table\Abstract.php(982): Zend_Db_Table_Abstract->_setupPrimaryKey()
#1 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table\Select.php(100): Zend_Db_Table_Abstract->info()
#2 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table\Select.php(78): Zend_Db_Table_Select->setTable(Object(Application_Model_DbTable_Guestbook))
#3 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table\Abstract.php(1018): Zend_Db_Table_Select->__construct(Object(Application_Model_DbTable_Guestbook))
#4 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table\Abstract.php(1326): Zend_Db_Table_Abstract->select()
#5 C:\wamp\www\zendtest\quickstart\application\models\GuestbookMapper.php(58): Zend_Db_Table_Abstract->fetchAll()
#6 C:\wamp\www\zendtest\quickstart\application\controllers\GuestbookController.php(14): Application_Model_GuestbookMapper->fetchAll()
#7 C:\wamp\www\zendtest\quickstart\library\Zend\Controller\Action.php(516): GuestbookController->indexAction()
#8 C:\wamp\www\zendtest\quickstart\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
#9 C:\wamp\www\zendtest\quickstart\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#10 C:\wamp\www\zendtest\quickstart\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#11 C:\wamp\www\zendtest\quickstart\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#12 C:\wamp\www\zendtest\quickstart\public\index.php(26): Zend_Application->run()
#13 {main}  
Request Parameters:

array (
  'controller' => 'guestbook',
  'action' => 'index',
  'module' => 'default',
)  

But I am sure my table has a primary key code for table:

CREATE TABLE guestbook (
    id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    email VARCHAR(32) NOT NULL DEFAULT 'noemail@test.com',
    comment TEXT NULL,
    created DATETIME NOT NULL
);

CREATE INDEX "id" ON "guestbook" ("id");

Don't understand why getting error

4

2 回答 2

1

在 Zend Framework 中,所有表都应该有主键列。在您的模型中,您应该设置主列的名称。

例如,表用户:

class Application_Model_TableUser extends Zend_Db_Table_Abstract
{
    protected $_name = 'user'; // table name
    protected $_primary = 'id'; // primary column name
}
于 2012-08-14T14:36:01.583 回答
0

我遇到了同样的错误。我发现 Zend 缓存了数据库元数据(显然是出于性能原因)。就我而言,我删除并创建了一个同名的表。新表有一个主列,而旧表没有。删除 Zend 缓存为我解决了这个问题。

于 2014-11-20T14:40:53.723 回答