I’m trying to update an existing Yii site, and I need to execute a DB migration.
I’ve added the migration by yii migrate/create
command, and execute SQL within it.
When I run yii migrate
, the migration content itself executes all right, I can see the new tables in the database.
But the migration command ends with an error
Exception 'yii\db\Exception' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "migration" does not exist
LINE 1: INSERT INTO "migration" ("version", "apply_time") VALUES ($1...
One of the last frames of the backtrace is the execution of function MigrateController::addMigrationHistory
.
At the beginning of that function I add:
yii\helpers\Console::output(print_r(['all tables' => $this->db->createCommand("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")->queryAll()], true));
When I run the migration, I get all the tables printed out, including migration
.
Still, the last statement in MigrateController::addMigrationHistory
– ->execute()
– throws the said exception.
What could be the problem here?
The whole stack trace:
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1303): PDOStatement->execute()
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute()
#2 /var/www/html/vendor/yiisoft/yii2/console/controllers/MigrateController.php(295): yii\db\Command->execute()
#3 /var/www/html/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(759): yii\console\controllers\MigrateController->addMigrationHistory()
#4 /var/www/html/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(216): yii\console\controllers\BaseMigrateController->migrateUp()
#5 [internal function]: yii\console\controllers\BaseMigrateController->actionUp()
#6 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#7 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#8 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(182): yii\base\Controller->runAction()
#9 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\console\Controller->runAction()
#10 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction()
#11 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction()
#12 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): yii\console\Application->handleRequest()
#13 /var/www/html/yii(23): yii\base\Application->run()
#14 {main}