简体   繁体   English

无法通过YIIC Migreate创建来创建表

[英]Not able to create Table through YIIC Migreate create

I just started learning YII framework and now I am facing an issue while trying to create table through YIIC MIGRATE. 我刚刚开始学习YII框架,现在在尝试通过YIIC MIGRATE创建表时遇到了一个问题。 Below is the code of my table. 下面是我表的代码。

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;
}
}

My project is under C:\\wamp\\www\\bookmyroom\\ and below is the folder structure 我的项目在C:\\ wamp \\ www \\ bookmyroom \\下,下面是文件夹结构

C:\\wamp\\www\\bookmyroom>dir Volume in drive C has no label. C:\\ wamp \\ www \\ bookmyroom> dir驱动器C中的卷没有标签。 Volume Serial Number is 5291-FE18 Directory of C:\\wamp\\www\\bookmyroom 卷序列号是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

I runned the YIIC MIgrate command inside the protected folder. 我在受保护的文件夹中运行了YIIC MIgrate命令。 I am getting the below error while running migrate command. 运行迁移命令时出现以下错误。

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}

Can you please check and let me know error which I am facing. 您能检查一下并让我知道我面临的错误吗? If there is any rectification require kindly let me know. 如果有任何纠正要求,请告诉我。

Try using execute 尝试使用执行

$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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM