我正在尝试使用Yii进行迁移,并在up()
方法中创建新表。只要我不添加ENGINE=InnoDB
子句,它就可以正常工作。在这种情况下,它会给我一个错误near ENGINE
。
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');
}
我的Yii版本是1.1.12。PHP 5.4.3,MySQL 5.5.24。
那是Yii虫吗?
EDIT(yii错误描述):
*** applying m130208_133533_create_table_project
> create table tbl_project ...exception 'CDbException' with message 'CDbComm
and failed to execute the SQL statement: CDbCommand failed to prepare the SQL st
atement: 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,
"name" varchar(255) 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' in C:'wamp'yii'framework'db'CDbCommand.php:357
我也遇到了同样的问题,通过检查console.php&main.php是相同的
i.e 'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=databasename',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'ur password',
'charset' => 'utf8',
),
并对两个文件中的sqlite行进行注释
使用"protected''yiic''migrate"作为控制台命令,使用protected''config''console.php,因此应该正确配置其"db"组件(如protected''coonfig''main.php所配置的)。如果您得到InnoDB错误,很可能您仍然被配置为SQLite。
尝试:
$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'
);
如果它不起作用,那么向我们显示MySql错误
另一种方法是在.env文件中包含:
DB_ENGINE=InnoDB