无法通过YIIC migrate create创建表
我刚刚开始学习YII框架,现在我在尝试通过YIIC迁移创建表时遇到了一个问题。下面是我表格的代码无法通过YIIC migrate create创建表,yii,migrate,yiic,Yii,Migrate,Yiic,我刚刚开始学习YII框架,现在我在尝试通过YIIC迁移创建表时遇到了一个问题。下面是我表格的代码 class m140627_072906_create_test_table extends CDbMigration { public function up() { $this->create('tbl_locations', array( 'id'=>'pk', 'l
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
你能检查一下,让我知道我面临的错误吗。如果有任何需要纠正的地方,请告诉我 尝试使用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");
大家好,我能解决这个问题。我是代码中的一个错误。我只是在代码中使用create而不是createTable。谢谢大家。谢谢,问题是我用了错误的代码create()而不是createTable(),而且我将尝试在将来的迁移表中使用您的代码。这段代码不起作用,它不是有效的SQL。您仍然拥有数组中的
=>
部分。
$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");