主键列 (id) 不是此表中的列 () [英] Primary key column(s) (id) are not columns in this table ()

查看:94
本文介绍了主键列 (id) 不是此表中的列 ()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注: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: 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:

But I am sure my table has a primary key id 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");

不明白为什么会出错.

我如何查看它是否甚至选择了正确的数据库

How can I see if it is even picking up the right database

推荐答案

Zend_Db_Table_Abstract 包含一个名为 _primary 的受保护属性,默认为 id.

Zend_Db_Table_Abstract contains a protected property called _primary which defaults to id.

它假设 id 是表的主键并且是一个序列(自动递增).

It assumes that id is the table's primary key and is a sequence (auto increment).

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

Since your table definition says that id is a primary key, you should get rid of the second SQL command that adds an index on the id column. Since its already a primary key, it is an index.

删除表并使用您在问题中的 create table 语句重新创建它,只是不要执行 CREATE INDEX 部分.之后,您应该可以继续.

Delete the table and re-create it using the create table statement you have in your question, just don't do the CREATE INDEX part. After that you should be able to continue.

这篇关于主键列 (id) 不是此表中的列 ()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆