Yii无法迁移我正确的课程

时间:2014-01-01 09:54:10

标签: php yii

我正在使用基于v1.1.14的Yii。我正在编写用于创建具有该字段的数据库表的函数。我的班级没有任何问题,其他任何人都可以成功迁移,但我不能。 在使用ts命名并配置main.php来创建数据库以引入数据库后,我在迁移时遇到错误。 我的迁移类是:

class m120509_224029_create_project_table extends CDbMigration
{
    public function up()
    {
        $this->createTable(
                 'tbl_project', 
                array(
                    'id' => 'pk',
                    'name' => 'string NOT NULL',
                    'description' => 'text NOT 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'
            );
    }

    public function down()
    {
        $this->dropTable('tbl_project');
    }
}

ERROR:

*** applying m140101_071345_tbl_project
    > create table tbl_project ...exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]: General error: 1 near "ENGINE": syntax error. The SQL statement executed was: CREATE TABLE 'tbl_project' (
        "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL
) ENGINE=InnoDB' in /var/www/yii/framework/db/CDbCommand.php:358
Stack trace:
#0 /var/www/yii/framework/db/CDbCommand.php(1324): CDbCommand->execute()
#1 /var/www/yii/framework/db/CDbMigration.php(233): CDbCommand->createTable('tbl_project', Array, 'ENGINE=InnoDB')
#2 /var/www/ts/protected/migrations/m140101_071345_tbl_project.php(9): CDbMigration->createTable('tbl_project', Array, 'ENGINE=InnoDB')
#3 /var/www/yii/framework/cli/commands/MigrateCommand.php(385): m140101_071345_tbl_project->up()
#4 /var/www/yii/framework/cli/commands/MigrateCommand.php(109): MigrateCommand->migrateUp('m140101_071345_...')
#5 [internal function]: MigrateCommand->actionUp(Array)
#6 /var/www/yii/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(MigrateCommand), Array)
#7 /var/www/yii/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)
#8 /var/www/yii/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
#9 /var/www/yii/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#10 /var/www/yii/framework/yiic.php(33): CApplication->run()
#11 /var/www/ts/protected/yiic.php(7): require_once('/var/www/yii/fr...')

2 个答案:

答案 0 :(得分:3)

使用命令行工具应用迁移时,yii使用配置文件console.php。只需将数据库配置从main.php复制到console.php,看看是否能解决问题。

答案 1 :(得分:0)

或者,确保您尚未创建将迁移设置为通过其他方法创建的表。

如果您已经通过MySQL或phpMyAdmin创建了tbl_project表,请删除该表(如果它为空),然后重新运行yii migrate以让您的迁移为您创建。