cms icon indicating copy to clipboard operation
cms copied to clipboard

[3.x]: Unable to apply migrations: Unknown column 'pluginId' in 'migrations'

Open lukastransom opened this issue 2 years ago • 7 comments

What happened?

Description

Whenever trying to perform php craft migrate/all on one of my projects, the following errors are output in the terminal:

*** applying m150403_183908_migrations_table_changes
    > add column type enum('app','plugin','content') NOT NULL DEFAULT 'app' AFTER `pluginId` to table {{%migrations}} ...Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pluginId' in 'migrations'
The SQL being executed was: ALTER TABLE `migrations` ADD `type` enum('app','plugin','content') NOT NULL DEFAULT 'app' AFTER `pluginId` (/var/www/html/vendor/yiisoft/yii2/db/Schema.php:678)
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE `mi...')
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('ALTER TABLE `mi...')
#2 /var/www/html/vendor/yiisoft/yii2/db/Migration.php(377): yii\db\Command->execute()
#3 /var/www/html/vendor/craftcms/cms/src/migrations/m150403_183908_migrations_table_changes.php(25): yii\db\Migration->addColumn('{{%migrations}}', 'type', Object(craft\db\mysql\ColumnSchemaBuilder))
#4 /var/www/html/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m150403_183908_migrations_table_changes->safeUp()
#5 /var/www/html/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(758): craft\db\Migration->up()
#6 /var/www/html/vendor/craftcms/cms/src/console/controllers/MigrateController.php(386): yii\console\controllers\BaseMigrateController->migrateUp('m150403_183908_...')
#7 [internal function]: craft\console\controllers\MigrateController->actionAll()
#8 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#10 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('all', Array)
#11 /var/www/html/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('all', Array)
#12 /var/www/html/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('migrate/all', Array)
#13 /var/www/html/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('migrate/all', Array)
#14 /var/www/html/vendor/yiisoft/yii2/console/Application.php(148): craft\console\Application->runAction('migrate/all', Array)
#15 /var/www/html/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(craft\console\Request))
#16 /var/www/html/craft(23): yii\base\Application->run()
#17 {main}
*** failed to apply m150403_183908_migrations_table_changes (time: 0.016s)

Looking at the database's migrations table, there is no such pluginId column. My other Craft projects (that successfully migrate) don't have this column either (their migrations table structure looks the same as this failing project).

Steps to reproduce

  1. php craft migrate/all

Expected behavior

Successfully apply pending migrations.

Actual behavior

Running php craft migrate/all fails and migrations remain unapplied.

Additional info

I've sent the complete project archive + DB backup to [email protected] on Apr 21, 2022 if that makes it easier to debug.

Craft CMS version

3.7.26

PHP version

8.0.16

Operating system and version

Ubuntu 20.04.4 LTS

Database type and version

MySQL 8.0.27

Image driver and version

Imagick 3.6.0 (ImageMagick 6.9.10-23)

Installed plugins and versions

"craftcms/ckeditor": "^1.1",
"craftcms/cms": "^3.7",
"craftcms/feed-me": "^4.4",
"craftcms/postmark": "^2.1",
"craftcms/redactor": "^2.10",
"doublesecretagency/craft-inventory": "^2.1",
"ether/tags": "^1.0",
"mmikkel/retcon": "^2.2",
"nystudio107/craft-imageoptimize": "^1.6.33",
"nystudio107/craft-minify": "^1.2",
"nystudio107/craft-retour": "^3.1",
"nystudio107/craft-seomatic": "^3.3.32",
"nystudio107/craft-vite": "^1.0",
"pennebaker/craft-architect": "^2.4",
"putyourlightson/craft-blitz": "^3.10",
"sebastianlenz/linkfield": "^2.0.0@beta",
"vaersaagod/dospaces": "^1.1",
"verbb/formie": "^1.4",
"verbb/navigation": "^1.4.13",
"verbb/super-table": "^2.6.7",
"vlucas/phpdotenv": "^3.4.0",
"yiisoft/yii2-redis": "^2.0.6"

lukastransom avatar May 04 '22 17:05 lukastransom

Which Craft version were you coming from?

Any chance you can share your prior DB backup, plus new Composer files? If se, please send them to [email protected] and we can try reproducing the same migrations on our end.

brandonkelly avatar May 05 '22 21:05 brandonkelly

Was there a solution for this? I'm running into the same error trying to get a Craft 3 install updated to the latest version before Craft 4.

heymarkreeves avatar Jun 20 '22 16:06 heymarkreeves

I've just inherited a Craft site and I'm getting NOT NULL DEFAULT 'app' AFTER `pluginId` to table {{%migrations}} every time a migration tries to run. V3.7.7

andrewhawkes avatar Jun 20 '22 18:06 andrewhawkes

So the above issue was happening when upgrading from 3.7.7 to the latest version. I've managed to update to a less new version to Craft 3.7.10. However, updating Craft 3.7.10 => 3.7.11 throws the error up with migrations as above.

I've managed to update all of the plugins which are listed below: Button Box 3.0.1 Content Security Policy 1.3.1 Formie 1.5.19 GDPR Cookie Consent 1.6.1 ImageOptimize 1.6.44 Knock Knock 1.2.16 Minify 1.2.11 Redactor 2.10.8 Redactor Custom Styles 3.0.4 Redirect Manager 1.1.1 Super Table 2.7.2 Tracker 3.0.0 Two-Factor Authentication 2.10.0 Typed link field 1.0.25 Video Embedder 1.1.4

andrewhawkes avatar Jun 20 '22 19:06 andrewhawkes

m150403_183908_migrations_table_changes is the very first (normal) migration listed in src/migrations/ for Craft 3. So I suspect that the issue here is that Craft isn’t able to identify which migrations have already been run, and thinks it’s supposed to start from the top – which would lead to an error like this if in reality the database was already migrated to a further point, as the current DB schema won’t be in the same state that the migration is expecting anymore.

Check your migrations database table. Is it empty by chance? That’s where Craft keeps its record of which migrations have already been run. If someone had emptied the table out, that would explain this.

If not, we can look into this further if someone can send us a (pre-update) database backup, plus your composer.json and composer.lock files, to [email protected].

brandonkelly avatar Jun 21 '22 03:06 brandonkelly

@brandonkelly - Thanks! This was a weird one as I took an existing codebase I use for plugin development and did an install on a clean database, but I also had some PHP version mismatches that affected the install/update process. Once I got the codebase updated, I started with a clean database again and didn't have this issue.

heymarkreeves avatar Jun 21 '22 11:06 heymarkreeves