代码之家  ›  专栏  ›  技术社区  ›  Ropstah

Doctrine MySQL150+表:生成模型有效,但反之亦然?

  •  1
  • Ropstah  · 技术社区  · 15 年前

    我可以基于现有数据库生成模型和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();
    
        }
    }
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   Ropstah    15 年前

    我将保留字用作列名(稍后也用作表名),Doctrine的'quoting'选项似乎没有自动打开….

    推荐文章