问题
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: 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',
)
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");
Don't understand why getting error.
How can I see if it is even picking up the right database
回答1:
Zend_Db_Table_Abstract
contains a protected property called _primary
which defaults to id
.
It assumes that id
is the table's primary key and is a sequence (auto increment).
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.
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.
回答2:
I think that your SQL schema is incorrect. Try to create table with primary kyy like this:
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)
);
回答3:
This error might be induced by (accidentally) using md5(null) as the cache ID. Or any other customary values, for that matter, e.g. 1, 0, true, false. However, null is very likely to be the culprit in this context, as it could be produced by an undefined variable.
A fix could be as simple as:
$cache = Zend_Registry::get('cache');
$cache->remove(md5(null));
回答4:
I had the same issue. The problem was that database was created in guestbook-dev.db instead of guestbook.db. You can check it by looking into this files. The solution was to change scripts/load.sqlite.php fromdefined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (null === $env) ? 'development' : $env);
to: defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (null === $env) ? 'production' : $env);
and, of course, running the script once again.
来源:https://stackoverflow.com/questions/11955062/primary-key-columns-id-are-not-columns-in-this-table