jeanluca
(Jeanluca)
February 16, 2011, 4:12pm
1
Hi All
I’ve my migration (only one table) ready. But when I execute it I get the following:
.../protected$ ./yiic migrate
Yii Migration Tool v1.0 (based on Yii v1.1.6)
Total 1 new migration to be applied:
m110216_150215_create_user_table
Apply the above migration? [yes|no] y
*** applying m110216_150215_create_user_table
> create table tbl_user ...exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]: General error: 1 table 'tbl_user' already exists' in /opt/software/yii/framework/db/CDbCommand.php:316
Stack trace:
#0 /opt/software/yii/framework/db/CDbCommand.php(1170): CDbCommand->execute()
#1 /opt/software/yii/framework/db/CDbMigration.php(150): CDbCommand->createTable(‘tbl_user’, Array, NULL)
#2 /opt/www/webapp/protected/migrations/m110216_150215_create_user_table.php(17): CDbMigration->createTable(‘tbl_user’, Array)
#3 /opt/softwaref/yii/framework/cli/commands/MigrateCommand.php(336): m110216_150215_create_user_table->up()
#4 /opt/software/yii/framework/cli/commands/MigrateCommand.php(99): MigrateCommand->migrateUp(‘m110216_150215_…’)
#5 [internal function]: MigrateCommand->actionUp(Array)
#6 /opt/software/yii/framework/console/CConsoleCommand.php(135): ReflectionMethod->invokeArgs(Object(MigrateCommand), Array)
#7 /opt/software/yii/framework/console/CConsoleCommandRunner.php(63): CConsoleCommand->run(Array)
#8 /opt/software/yii/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)
#9 /opt/software/yii/framework/base/CApplication.php(155): CConsoleApplication->processRequest()
#10 /opt/software/yii/framework/yiic.php(33): CApplication->run()
#11 /opt/www/webapp/protected/yiic.php(7): require_once(’/opt/www/…’)
#12 /opt/www/webapp/protected/yiic(4): require_once(’/opt/www/…’)
I get the impression it has a problem with a table which already exists and has the same name. However, there are no tables in that database at all!!
For the migration I only created the migration directory and in there I have the the following file
m110216_150215_create_user_table
<?php
class m110216_150215_create_user_table extends CDbMigration
{
public function up()
{
$this->createTable('tbl_user', array(
'id' => 'pk',
'name' => 'string NOT NULL',
'surname' => 'string NOT NULL',
'organisation' => 'string NOT NULL',
'email' => 'string NOT NULL',
'phone' => 'string NOT NULL',
'created_time' => 'timestamp NOT NULL DEFAULT "0000-00-00 00:00:00"',
'update_time' => 'timestamp NOT NULL DEFAULT "0000-00-00 00:00:00" ON UPDATE CURRENT_TIMESTAMP',
));
}
public function down()
{
$this->dropTable('tbl_user');
}
}
Any suggestion why I get this error ?
jeanluca
(Jeanluca)
February 16, 2011, 7:47pm
2
I found it. In config/console.php you need to define the connection again. In there it was set to sqlite. I found out because I noticed in protected/data a file testdrive.db was created!