Doctrine 1.2 不从 Zend Framework 中的模型创建表

发布于 2024-11-30 22:53:34 字数 3349 浏览 5 评论 0原文

我正在尝试使用以下方法从模型创建表:

Doctrine::createTablesFromModels(APPLICATION_PATH . '/models');

与从 Yaml 文件生成模型(效果很好)不同,这根本不执行任何操作。没有错误,没有警告,什么都没有。未创建表。如果我运行下面的代码,它也可以正常工作:

Doctrine::dropDatabases();

因此数据库连接确实有效并且权限设置正确。我已经用十种不同的方式谷歌搜索了它,但没有得到任何有用的答案,所以现在我在这里问。

这是我的基类之一:

<?php

/**
 * BaseUser
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @property string $email
 * @property string $password
 * @property string $firstName
 * @property string $lastName
 * @property string $profileText
 * @property integer $role_id
 * @property Role $Role
 * @property Doctrine_Collection $UserDetail
 * @property Doctrine_Collection $CalendarItem
 * @property Doctrine_Collection $NewsItem
 * @property Doctrine_Collection $Link
 * @property Doctrine_Collection $TwitterUser
 * @property Doctrine_Collection $Tweet
 * 
 * @package    ##PACKAGE##
 * @subpackage ##SUBPACKAGE##
 * @author     ##NAME## <##EMAIL##>
 * @version    SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
 */
abstract class BaseUser extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('user');
        $this->hasColumn('email', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('password', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('firstName', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('lastName', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('profileText', 'string', null, array(
             'type' => 'string',
             'length' => '',
             ));
        $this->hasColumn('role_id', 'integer', 8, array(
             'type' => 'integer',
             'length' => 8,
             ));

        $this->option('collate', 'utf8_unicode_ci');
        $this->option('charset', 'utf8');
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasOne('Role', array(
             'local' => 'role_id',
             'foreign' => 'id'));

        $this->hasMany('UserDetail', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('CalendarItem', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('NewsItem', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('Link', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('TwitterUser', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('Tweet', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $timestampable0 = new Doctrine_Template_Timestampable();
        $softdelete0 = new softDelete();
        $this->actAs($timestampable0);
        $this->actAs($softdelete0);
    }
}

I'm trying to create tables from models by using:

Doctrine::createTablesFromModels(APPLICATION_PATH . '/models');

Unlike generating the models from a Yaml file, which worked just fine, this does nothing at all. No errors, no warnings, nothing. The tables are not created. If I run the code below, it works just fine too:

Doctrine::dropDatabases();

So the database connection does work and the permissions are setup right. I've googled it in ten different ways without getting any helpful answers, so now I'm asking here.

Here is one of my base classes:

<?php

/**
 * BaseUser
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @property string $email
 * @property string $password
 * @property string $firstName
 * @property string $lastName
 * @property string $profileText
 * @property integer $role_id
 * @property Role $Role
 * @property Doctrine_Collection $UserDetail
 * @property Doctrine_Collection $CalendarItem
 * @property Doctrine_Collection $NewsItem
 * @property Doctrine_Collection $Link
 * @property Doctrine_Collection $TwitterUser
 * @property Doctrine_Collection $Tweet
 * 
 * @package    ##PACKAGE##
 * @subpackage ##SUBPACKAGE##
 * @author     ##NAME## <##EMAIL##>
 * @version    SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
 */
abstract class BaseUser extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('user');
        $this->hasColumn('email', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('password', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('firstName', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('lastName', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('profileText', 'string', null, array(
             'type' => 'string',
             'length' => '',
             ));
        $this->hasColumn('role_id', 'integer', 8, array(
             'type' => 'integer',
             'length' => 8,
             ));

        $this->option('collate', 'utf8_unicode_ci');
        $this->option('charset', 'utf8');
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasOne('Role', array(
             'local' => 'role_id',
             'foreign' => 'id'));

        $this->hasMany('UserDetail', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('CalendarItem', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('NewsItem', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('Link', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('TwitterUser', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('Tweet', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $timestampable0 = new Doctrine_Template_Timestampable();
        $softdelete0 = new softDelete();
        $this->actAs($timestampable0);
        $this->actAs($softdelete0);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独木成林 2024-12-07 22:53:34

问题已经解决了。我正在使用软删除功能,但忘记设置:

$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);

这是软删除工作所必需的。我还发现在我生成的模型中它使用了错误的软删除代码:

$softdelete0 = new softDelete();

而不是:

$softdelete0 = new Doctrine_Template_SoftDelete();

The problem has been solved. I was using the softdelete functionality and I forgot to set:

$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);

This is necessary for softdelete to work. I also found out that in my generated models it used the wrong code for softdeletion:

$softdelete0 = new softDelete();

Instead of:

$softdelete0 = new Doctrine_Template_SoftDelete();
总攻大人 2024-12-07 22:53:34

我之前就遇到过这个问题,经过三天的搜索,我找不到解决方案
最后我转而使用 symfony cli 工具生成 sql 并从 yaml 文件创建数据库

I had face this issue before that and after 3 days of searching i couldn't find a solution
at the end of it i had moved to use symfony cli tool to generate sql and create db from yaml file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文