dgrigg / Craft-Migration-Manager

Deprecated - Migration Manager for Craft CMS
MIT License
39 stars 15 forks source link

MigrationException when trying to migrate from one server to another #18

Closed urbantrout closed 6 years ago

urbantrout commented 6 years ago

I am trying to run a migration. The migration was created on the production server and copied to my local dev server.

Setup

Live server

Dev server

Exceptions

Whenever I try to run the migration I get the following Internal Server Error:

Next craft\errors\MigrationException: An error occurred while executing the "craft\contentmigrations\m180614_101121_migration_global_cookieDisclaimer_footer_navigationSecondary_navigationPrimary_jobOffers migration: SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "ut_content_elementId_siteId_unq_idx"
DETAIL:  Key ("elementId", "siteId")=(13, 1) already exists.
The SQL being executed was: UPDATE "ut_content" SET "elementId"=13, "siteId"=1, "dateUpdated"='2018-06-14 08:19:33' WHERE "id"=13 in /var/www/html/vendor/craftcms/cms/src/db/MigrationManager.php:260

And on some other migrations I only get this, which does not provide any useful hints (at least for me)

2018-06-14 10:24:35 [127.0.0.1][1][-][error][craft\db\MigrationManager::migrateUp] Failed to apply m180614_095733_migration_live (time: 2.686s). Output:

2018-06-14 10:24:35 [127.0.0.1][1][-][error][craft\errors\MigrationException] craft\errors\MigrationException: An error occurred while executing the "craft\contentmigrations\m180614_095733_migration_live migration. in /var/www/html/vendor/craftcms/cms/src/db/MigrationManager.php:260
Stack trace:
#0 /var/www/html/vendor/firstborn/migrationmanager/src/services/Migrations.php(327): craft\db\MigrationManager->migrateUp(Object(craft\contentmigrations\m180614_095733_migration_live))
#1 /var/www/html/vendor/firstborn/migrationmanager/src/controllers/RunController.php(109): firstborn\migrationmanager\services\Migrations->runMigrations(Array)
#2 [internal function]: firstborn\migrationmanager\controllers\RunController->actionMigrations()
#3 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#4 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#5 /var/www/html/vendor/craftcms/cms/src/web/Controller.php(103): yii\base\Controller->runAction('migrations', Array)
#6 /var/www/html/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('migrations', Array)
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(273): yii\base\Module->runAction('migrationmanage...', Array)
#8 /var/www/html/vendor/craftcms/cms/src/web/Application.php(521): craft\web\Application->runAction('migrationmanage...', Array)
#9 /var/www/html/vendor/craftcms/cms/src/web/Application.php(257): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#10 /var/www/html/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#11 /var/www/html/web/index.php(21): yii\base\Application->run()
#12 {main}
fb-derrick-grigg commented 6 years ago

@urbantrout what type of data are attempting to migrate? Looks like it might be global fields? Is it just fields or content?

urbantrout commented 6 years ago

Sorry for the late reply!

This particular migration only consists of global fields.

dgrigg commented 6 years ago

@urbantrout is this issue with global migrations still happening. Tested locally and all is good.

roelvanhintum commented 6 years ago

@dgrigg I'm having kind of the same issue with a migration where i'm adding a field to existing globals.

Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '15-1' for key 'craft_content_elementId_siteId_unq_idx'
The SQL being executed was: UPDATE `craft_content` SET `elementId`=15, `siteId`=1, `dateUpdated`='2018-10-22 09:27:37' WHERE `id`='15' (/var/www/vendor/yiisoft/yii2/db/Schema.php:664)
#0 /var/www/vendor/yiisoft/yii2/db/Command.php(1263): yii\db\Schema->convertException(Object(PDOException), 'UPDATE `craft_c...')
#1 /var/www/vendor/yiisoft/yii2/db/Command.php(1075): yii\db\Command->internalExecute('UPDATE `craft_c...')
#2 /var/www/vendor/craftcms/cms/src/services/Content.php(191): yii\db\Command->execute()
#3 /var/www/vendor/craftcms/cms/src/services/Elements.php(486): craft\services\Content->saveContent(Object(craft\elements\GlobalSet))
#4 /var/www/vendor/craftcms/cms/src/services/Globals.php(354): craft\services\Elements->saveElement(Object(craft\elements\GlobalSet), false)
#5 /var/www/vendor/firstborn/migrationmanager/src/services/Globals.php(76): craft\services\Globals->saveSet(Object(craft\elements\GlobalSet))
#6 /var/www/vendor/firstborn/migrationmanager/src/services/BaseMigration.php(147): firstborn\migrationmanager\services\Globals->importItem(Array)
#7 /var/www/vendor/firstborn/migrationmanager/src/services/Migrations.php(264): firstborn\migrationmanager\services\BaseMigration->import(Array)
#8 /var/www/migrations/m181022_104022_migration_AddedLogoFields.php(40): firstborn\migrationmanager\services\Migrations->import(Array)
#9 /var/www/vendor/craftcms/cms/src/db/Migration.php(56): craft\contentmigrations\m181022_104022_migration_AddedLogoFields->safeUp()
#10 /var/www/vendor/craftcms/cms/src/db/MigrationManager.php(243): craft\db\Migration->up(true)
#11 /var/www/vendor/craftcms/cms/src/db/MigrationManager.php(163): craft\db\MigrationManager->migrateUp(Object(craft\contentmigrations\m181022_104022_migration_AddedLogoFields))
#12 /var/www/vendor/craftcms/cms/src/services/Updates.php(210): craft\db\MigrationManager->up()
#13 /var/www/vendor/craftcms/cms/src/console/controllers/MigrateController.php(243): craft\services\Updates->runMigrations(Array)
#14 [internal function]: craft\console\controllers\MigrateController->actionAll()
#15 /var/www/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /var/www/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#17 /var/www/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('all', Array)
#18 /var/www/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#19 /var/www/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#20 /var/www/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('migrate/all', Array)
#21 /var/www/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#22 /var/www/craft(23): yii\base\Application->run()
#23 {main}
Exception 'craft\errors\MigrateException' with message 'An error occurred while migrating Craft CMS.'

in /var/www/vendor/craftcms/cms/src/services/Updates.php:223
dgrigg commented 6 years ago

@roelvanhintum thanks for the PR, all good