when I run php yii migrat shell throw error “table already exists”
curder opened this issue · comments
curder commented
when i run php yii migrate --migrationPath=@vendor/yii2mod/yii2-comments/migrations
,throw some error, Error Info :
rename table {{%Comment}} to {{%comment}} ...Exception 'yii\db\Exception' with message 'SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'blog_comment' already exists
The SQL being executed was: RENAME TABLE `blog_Comment` TO `blog_comment`'
My Developer environment is MAMP,and the MySQL version is 5.5.42。
so I modified the my.conf file and restart mysqld server.
[mysqld]
lower_case_table_names = 0
the bug is aways ready exists,please tell me some idea to solve it.
Ihor Chepurnyi commented
Hi, blog_
is your prefix for all tables?
curder commented
yes, I defined it in my config file,tablePrefix => blog_
for my database connect params, and I am run php yii migrate/create init_comment_table
to created a new migration for this problem. like this
<?php
use yii\db\Migration;
class m170313_042335_init_comment_table extends Migration
{
const TABLE_NAME = '{{%comment}}';
public function up()
{
echo "m170313_042335_init_comment_table cannot be reverted.\n";
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable(self::TABLE_NAME, [
'id' => $this->primaryKey(),
'entity' => $this->char(10)->notNull(),
'entityId' => $this->integer()->notNull(),
'content' => $this->text()->notNull(),
'parentId' => $this->integer()->null(),
'level' => $this->smallInteger()->notNull()->defaultValue(1),
'createdBy' => $this->integer()->notNull(),
'updatedBy' => $this->integer()->notNull(),
'relatedTo' => $this->string(500)->notNull(),
'url' => $this->text(),
'status' => $this->smallInteger()->notNull()->defaultValue(1),
'createdAt' => $this->integer()->notNull(),
'updatedAt' => $this->integer()->notNull(),
], $tableOptions);
$this->createIndex('idx-comment-entity', self::TABLE_NAME, 'entity');
$this->createIndex('idx-comment-status', self::TABLE_NAME, 'status');
}
public function down()
{
echo "m170313_042335_init_comment_table cannot be reverted.\n";
$this->dropTable(self::TABLE_NAME);
}
}
and solved it, thank you for your answer! Happy Hacking :laugh
Ihor Chepurnyi commented
Thanks :)