Reputation: 17303
i'm using Yii based on v1.1.14. i'm writing up function to create database table with thats fields. my class is not any problem and other anybody can migrate that successfull but i can not.
after create database with ts
named and configure main.php
for introducing databse i get error in migration.
my migrate class is :
class m120509_224029_create_project_table extends CDbMigration
{
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'
);
}
public function down()
{
$this->dropTable('tbl_project');
}
}
ERROR:
*** applying m140101_071345_tbl_project
> create table tbl_project ...exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: 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
) ENGINE=InnoDB' in /var/www/yii/framework/db/CDbCommand.php:358
Stack trace:
#0 /var/www/yii/framework/db/CDbCommand.php(1324): CDbCommand->execute()
#1 /var/www/yii/framework/db/CDbMigration.php(233): CDbCommand->createTable('tbl_project', Array, 'ENGINE=InnoDB')
#2 /var/www/ts/protected/migrations/m140101_071345_tbl_project.php(9): CDbMigration->createTable('tbl_project', Array, 'ENGINE=InnoDB')
#3 /var/www/yii/framework/cli/commands/MigrateCommand.php(385): m140101_071345_tbl_project->up()
#4 /var/www/yii/framework/cli/commands/MigrateCommand.php(109): MigrateCommand->migrateUp('m140101_071345_...')
#5 [internal function]: MigrateCommand->actionUp(Array)
#6 /var/www/yii/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(MigrateCommand), Array)
#7 /var/www/yii/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)
#8 /var/www/yii/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
#9 /var/www/yii/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#10 /var/www/yii/framework/yiic.php(33): CApplication->run()
#11 /var/www/ts/protected/yiic.php(7): require_once('/var/www/yii/fr...')
Upvotes: 0
Views: 482
Reputation: 1
Alternatively, make sure you haven't already created the table that your migration is set to create via another method.
If you already created the tbl_project
table via MySQL or phpMyAdmin or something, drop that table (if it's empty) and then rerun yii migrate
to let your migration create it for you.
Upvotes: 0
Reputation: 351
When you apply the migrations with the command line tool, yii uses the configuration file console.php
. Just copy the DB configuration from main.php
to console.php
and see if that solves the problem.
Upvotes: 3