我可以基于现有数据库生成我的模型和schema.yml文件。但是,当我尝试使用Doctrine::createTablesFromModels()
的另一种方式时,我得到一个错误:
语法错误或访问冲突:1064
所以这些都有效:
Doctrine::generateYamlFromDb(APPPATH . 'models/yaml');
Doctrine::generateYamlFromModels(APPPATH . 'models/yaml', APPPATH . 'models');
Doctrine::generateModelsFromYaml(APPPATH . 'models/yaml', APPPATH . 'models', array('generateTableClasses' => true));
Doctrine::generateModelsFromDb(APPATH . 'models', array('default'), array('generateTableClasses' => true));
但是这失败了(它丢弃/创建数据库和大约50个表):
Doctrine::dropDatabases();
Doctrine::createDatabases();
Doctrine::createTablesFromModels();
部分输出的SQL查询显示错误在Notification
对象周围,如下所示:
任何线索都会受到高度赞赏!
<?php
// Connection Component Binding
Doctrine_Manager::getInstance()->bindComponent('Notification', 'default');
/**
* BaseNotification
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @property integer $n_auto_key
* @property integer $type
* @property string $title
* @property string $message
* @property timestamp $entry_date
* @property timestamp $update_date
* @property integer $u_auto_key
* @property integer $c_auto_key
* @property integer $ub_auto_key
* @property integer $o_auto_key
* @property integer $notified
* @property integer $read
* @property integer $urgence
*
* @package ##PACKAGE##
* @subpackage ##SUBPACKAGE##
* @author ##NAME## <##EMAIL##>
* @version SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
*/
abstract class BaseNotification extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('Notification');
$this->hasColumn('n_auto_key', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
'length' => '4',
));
$this->hasColumn('type', 'integer', 1, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '1',
));
$this->hasColumn('title', 'string', 50, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '50',
));
$this->hasColumn('message', 'string', null, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('entry_date', 'timestamp', 25, array(
'type' => 'timestamp',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '25',
));
$this->hasColumn('update_date', 'timestamp', 25, array(
'type' => 'timestamp',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '25',
));
$this->hasColumn('u_auto_key', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '4',
));
$this->hasColumn('c_auto_key', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '4',
));
$this->hasColumn('ub_auto_key', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '4',
));
$this->hasColumn('o_auto_key', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '4',
));
$this->hasColumn('notified', 'integer', 1, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => true,
'autoincrement' => false,
'length' => '1',
));
$this->hasColumn('read', 'integer', 1, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => true,
'autoincrement' => false,
'length' => '1',
));
$this->hasColumn('urgence', 'integer', 1, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => true,
'autoincrement' => false,
'length' => '1',
));
}
public function setUp()
{
parent::setUp();
}
}
答案 0 :(得分:1)
我使用保留字作为列名(稍后也作为表名),而且Doctrine的“引用”选项似乎没有自动打开....