Doctrine 1.2 不从 Zend Framework 中的模型创建表
我正在尝试使用以下方法从模型创建表:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题已经解决了。我正在使用软删除功能,但忘记设置:
这是软删除工作所必需的。我还发现在我生成的模型中它使用了错误的软删除代码:
而不是:
The problem has been solved. I was using the softdelete functionality and I forgot to set:
This is necessary for softdelete to work. I also found out that in my generated models it used the wrong code for softdeletion:
Instead of:
我之前就遇到过这个问题,经过三天的搜索,我找不到解决方案
最后我转而使用 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