1

我刚开始学习 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:\wamp\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 命令。运行迁移命令时出现以下错误。

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}

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

4

1 回答 1

-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");
于 2014-06-27T08:06:36.777 回答