无法通过YII迁移创建表创建

时间:2014-06-27 07:58:42

标签: yii migrate yiic

我刚刚开始学习YII框架,现在我在尝试通过YIIC MIGRATE创建表时遇到了问题。下面是我的表格的代码。

class m140627_072906_create_test_table extends CDbMigration
{
   public function up()
   {
        $this->create('tbl_locations',
            array(
                'id'=>'pk',
                'location_name'=>'string NOT NULL',
                'create_time'=>'datetime NOT NULL',
                'create_user_id'=>'int(11) NOT NULL',
                'update_time'=>'datetime NOT NULL',
                'update_user_id'=>'int(11) NOT NULL',
            ), 'ENGINE=InnoDB'
        );
}
}
public function down()
{
    echo "m140627_072906_create_test_table does not support migration down.\n";
    return false;
}
}

我的项目在C:\ wamp \ www \ bookmyroom \下面,下面是文件夹结构

C:\瓦帕\ WWW \ bookmyroom> DIR  驱动器C中的卷没有标签。  卷序列号为5291-FE18     目录C:\ wamp \ www \ bookmyroom

06/25/2014  08:58 PM    <DIR>          .
06/25/2014  08:58 PM    <DIR>          ..    
06/27/2014  12:32 PM    <DIR>          assets
06/25/2014  07:05 PM    <DIR>          css
06/25/2014  09:04 PM    <DIR>          framework
06/25/2014  07:05 PM    <DIR>          images
06/25/2014  07:05 PM               466 index-test.php
06/25/2014  09:10 PM               456 index.php
06/25/2014  07:08 PM    <DIR>          nbproject
06/25/2014  07:05 PM    <DIR>          protected
06/25/2014  07:05 PM    <DIR>          themes
               2 File(s)            922 bytes
               9 Dir(s)   8,986,624,000 bytes free

我在受保护的文件夹中运行了YIIC MIgrate命令。我在运行migrate命令时收到以下错误。

C:\wamp\www\bookmyroom\protected>YIIC Migrate

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

Total 1 new migration to be applied:
m140627_074906_create_table_locations

Apply the above migration? (yes|no) [no]:y
*** applying m140627_074906_create_table_locations
exception 'CException' with message 'm140627_074906_create_table_locations and its    
behaviors do not have a method or closure named "create".' in 
C:\wamp\www\yii\framework\base\CComponent.php:266
Stack trace:
#0         
C:\wamp\www\bookmyroom\protected\migrations\m140627_074906_create_table_locations.php
(16): CComponent->__call('create', Array)
#1             
C:\wamp\www\bookmyroom\protected\migrations\m140627_074906_create_table_locations.php
(16): m140627_074906_create_table_locations->create('tbl_locat
ions', Array, 'ENGINE=InnoDB')
#2 C:\wamp\www\yii\framework\cli\commands\MigrateCommand.php(385):            
m140627_074906_create_table_locations->up()
#3 C:\wamp\www\yii\framework\cli\commands\MigrateCommand.php(109): 
MigrateCommand->migrateUp('m140627_074906_...')
#4 [internal function]: MigrateCommand->actionUp(Array)
#5 C:\wamp\www\yii\framework\console\CConsoleCommand.php(172): 
ReflectionMethod->invokeArgs(Object(MigrateCommand), Array)
#6 C:\wamp\www\yii\framework\console\CConsoleCommandRunner.php(71): 
CConsoleCommand->run(Array)
#7 C:\wamp\www\yii\framework\console\CConsoleApplication.php(92): 
CConsoleCommandRunner->run(Array)
#8 C:\wamp\www\yii\framework\base\CApplication.php(180): 
CConsoleApplication->processRequest()
#9 C:\wamp\www\yii\framework\yiic.php(33): CApplication->run()
#10 C:\wamp\www\bookmyroom\protected\yiic.php(7): require_once('C:\wamp\www\yii...')
#11 {main}

请您检查并告诉我我所面临的错误。如果有任何整改需要请让我知道。

1 个答案:

答案 0 :(得分:-2)

尝试使用执行

$this->execute("CREATE TABLE `tbl_locations` (
                'location_name'=>'string NOT NULL',
                'create_time'=>'datetime NOT NULL',
                'create_user_id'=>'int(11) NOT NULL',
                'update_time'=>'datetime NOT NULL',
                'update_user_id'=>'int(11) NOT NULL'
                PRIMARY KEY (`id`),
        ) ENGINE=InnoDB");
相关问题