php – Yii Migration,不创建表

我是Yii的新手(Still Learning)我正在学习一本书
在这里,我按照书中所写的创建了一个新的迁移

yiic migrate create create_issue_user_and_assignment_tables

并在安全方面我写了这个查询

$this->createTable('tbl_issue', array(
'id' => 'pk',
'name' => 'string NOT NULL',
'description' => 'text',
'project_id' => 'int(11) DEFAULT NULL',
'type_id' => 'int(11) DEFAULT NULL',
'status_id' => 'int(11) DEFAULT NULL',
'owner_id' => 'int(11) DEFAULT NULL',
'requester_id' => 'int(11) DEFAULT NULL',
'create_time' => 'datetime DEFAULT NULL',
'create_user_id' => 'int(11) DEFAULT NULL',
'update_time' => 'datetime DEFAULT NULL',
'update_user_id' => 'int(11) DEFAULT NULL',
), 'ENGINE=InnoDB');
//create the user table
$this->createTable('tbl_user', array(
'id' => 'pk',
'username' => 'string NOT NULL',
'email' => 'string NOT NULL',
'password' => 'string NOT NULL',
'last_login_time' => 'datetime DEFAULT NULL',
'create_time' => 'datetime DEFAULT NULL',
'create_user_id' => 'int(11) DEFAULT NULL',
'update_time' => 'datetime DEFAULT NULL',
'update_user_id' => 'int(11) DEFAULT NULL',
), 'ENGINE=InnoDB');

这在safeDown()

$this->dropTable('tbl_issue');
$this->dropTable('tbl_user');

然后运行它并得到以下消息

D:\wamp\www\yiisite\protected>yiic migrate
PHP Deprecated:  Directive 'register_globals' is deprecated in PHP 5.3 and great
er in UnkNown on line 0

Deprecated: Directive 'register_globals' is deprecated in PHP 5.3 and greater in
 UnkNown on line 0

Yii Migration Tool v1.0 (based on Yii v1.1.13)

Total 1 new migration to be applied:
    m130703_085302_create_issue_user_and_assignment_tables

Apply the above migration? (yes|no) [no]:yes
*** applying m130703_085302_create_issue_user_and_assignment_tables
*** applied m130703_085302_create_issue_user_and_assignment_tables (time: 0.042s
)


Migrated up successfully.

现在的问题是,数据库中没有创建表,因为msg不推荐使用register_globals,但我不知道该怎么做,连接参数是正确的,并且在表tbl_migration中插入了一条记录

m130703_085302_create_issue_user_and_assignment_ta...   1372842220

但是没有创建新表.

解决方法:

创建表通常不需要事务

<?PHP
class m130630_124600_some_description_name extends CDbMigration
{
    public function up(){
        //upcode example create the session table
        $this->createTable('session',[
             'id' => "varchar(40) NOT NULL",
             'expire' => "int(12)",
             'data' => "blob",
        ]);
        $this->addPrimaryKey('idx','session','id');
    }
    public function down(){
       // downcode (undo the up code) example: drop session table
       $this->dropTable('session');
    }
}

如果需要交易

遵循safeUp的评论

This method contains the logic to be executed when applying this
migration. This method differs from up() in that the DB logic
implemented here will be enclosed within a DB transaction. Child
classes may implement this method instead of up() if the DB logic
needs to be within a transaction.

相关文章

1、将Yii2.0advanced版中应用主体frontend或backend应用复制...
Yii2restfulAPI文档一、配置模块:1.Config/main.php:  2...
Yii在framework/i18n/data/%lang%.php文件中有很多翻译.这...
在Yii2中,官方的页面多语言解决方案有两个:方案1,使用Yii...
Yii2.0对数据库查询的一些简单的操作1234567891011121314151...
数据查询User::find()->all();此方法返回所有数据;User:...