Doctrine试图选择一个不存在的列

时间:2010-11-12 15:27:24

标签: php zend-framework doctrine

我的模特

<?php
// Connection Component Binding
Doctrine_Manager::getInstance()->bindComponent('Identiti_Model_Akses', 'doctrine');

/**
 * Identiti_Model_BaseAkses
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @property string $nostaf
 * @property integer $id_aplikasi
 * 
 * @package    ##PACKAGE##
 * @subpackage ##SUBPACKAGE##
 * @author     ##NAME## <##EMAIL##>
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
abstract class Identiti_Model_BaseAkses extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('akses');
        $this->hasColumn('nostaf', 'string', 12, array(
             'type' => 'string',
             'length' => 12,
             'fixed' => false,
             'unsigned' => false,
             'primary' => false,
             'notnull' => true,
             'autoincrement' => false,
             ));
        $this->hasColumn('id_aplikasi', 'integer', 4, array(
             'type' => 'integer',
             'length' => 4,
             'fixed' => false,
             'unsigned' => false,
             'primary' => false,
             'notnull' => true,
             'autoincrement' => false,
             ));
    }

    public function setUp()
    {
        parent::setUp();
    }
}

我的实际表格:

mysql> desc akses;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| nostaf      | varchar(12) | NO   |     | NULL    |       |
| id_aplikasi | int(11)     | NO   |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+

我的代码:

$q = Doctrine_Query::create()                  
      ->from('Identiti_Model_Akses a');
$result = $q->execute();

我的错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a.id' in 'field list'. Failing Query: "SELECT a.id AS a__id, a.nostaf AS a__nostaf, a.id_aplikasi AS a__id_aplikasi FROM akses a" 

我认为它与表本身有关(它没有任何主键)。我已经尝试将其中一个设置为主键,并且查询不再输出相同的错误。

1 个答案:

答案 0 :(得分:2)

Doctrine要求设置主键。默认情况下,如果您没有一个集合,它将假定'id'是PK并尝试选择它。没有解决这个问题的方法。你最好添加一个带有自动增量的PK。