Zend framework 主键列(id)不是此表()中的列

Zend framework 主键列(id)不是此表()中的列,zend-framework,primary-key,wamp,Zend Framework,Primary Key,Wamp,我正在跟踪: 不断地碰到一堆又一堆的问题。我当前的错误如下: An error occurred Application error Exception information: Message: Primary key column(s) (id) are not columns in this table () Stack trace: #0 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table\Abstract.php

我正在跟踪:

不断地碰到一堆又一堆的问题。我当前的错误如下:

    An error occurred

Application error

Exception information:

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

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',
)  
但我确信我的表具有表的主键id:

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");
不明白为什么会出错


我怎么才能知道它是否选择了正确的数据库

Zend\u Db\u Table\u Abstract
包含一个名为
\u primary
的受保护属性,该属性默认为
id

它假定
id
是表的主键,是一个序列(自动递增)

因为您的表定义表明
id
是主键,所以应该去掉在
id
列上添加索引的第二个SQL命令。因为它已经是主键,所以它是一个索引


删除该表并使用问题中的CREATETABLE语句重新创建它,只是不要执行
CREATEINDEX
部分。之后,您应该可以继续。

我认为您的SQL模式不正确。尝试使用主kyy创建表,如下所示:

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

此错误可能是(意外地)使用md5(null)作为缓存ID或任何其他常用值(例如1、0、true、false)引起的。然而,在这种情况下,null很可能是罪魁祸首,因为它可能由未定义的变量生成

修复方法可以简单到:

    $cache = Zend_Registry::get('cache');
    $cache->remove(md5(null));

我也有同样的问题。问题是数据库是在guestbook-dev.db而不是guestbook.db中创建的。你可以通过查看这些文件来检查它。解决方案是将scripts/load.sqlite.php从
已定义('APPLICATION_ENV'))
||定义('APPLICATION_ENV',(null===$ENV)?'development':$ENV)
致:
已定义('APPLICATION_ENV'))
||定义('APPLICATION_ENV',(null===$ENV)?'production':$ENV)

当然,还要再次运行脚本。

检查列名后是否有尾随空格,并请发布查询的输出
SHOW CREATE TABLE guestbook
,这样我们就可以再次检查实际结构。如何使用cmd promtwe再次显示输出!:)。。。因为您使用的是wamp,所以必须在系统上安装phpmyadmin。转到,您可以在左侧看到所有数据库,单击您的数据库。然后,会有一个名为SQL的选项卡,你可以把@TimFountain的命令放在那里,告诉我们输出是什么。。。另外,请确保表中有一些数据:)因此,我们一直在仔细研究它,似乎它甚至没有创建数据库,尽管它说它创建了。考虑重新安装wamp并重新启动