Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with migrations on site. #5222

Closed
mdunbavan opened this issue Nov 8, 2019 · 5 comments
Closed

Issue with migrations on site. #5222

mdunbavan opened this issue Nov 8, 2019 · 5 comments
Assignees

Comments

@mdunbavan
Copy link

@mdunbavan mdunbavan commented Nov 8, 2019

Description

I had a site that I was working on that was running on a staging server. I had updated composer packages on the site and I had also synced project config. I then went into settings and sites to make sure the url for the main site was correct. Once I changed it I hit Save.

Immediately after that I hit an error which gave me this:

87-a953-e2414850de29', `fieldVersion`='zjQmAyukxkIg', `dateUpdated`='2019-04-16 12:23:39', `dateCreated`='2017-07-07 11:35:13''

in /srv/app/viaduct/htdocs/vendor/yiisoft/yii2/db/Schema.php:664

Error Info:
Array
(
    [0] => 23000
    [1] => 1062
    [2] => Duplicate entry '1' for key 'PRIMARY'
)

Stack trace:
#0 /srv/app/viaduct/htdocs/vendor/yiisoft/yii2/db/Command.php(1295): yii\db\Schema->convertException(Object(PDOException), 'UPDATE `craft_i...')

I had a chat with fellow devs on Discord and one user had the dame issues from time to time.

Steps to reproduce

  1. Import a new DB dump into the DB on the server and do the necessary steps to get a site up and running.
  2. Run composer install or composer update to get dependancies setup and the site working as expected on the staging server.
  3. Push some code up to the remote server.
  4. error starts from there

Additional info

  • Craft version: latest C3
  • PHP version: 7.3
  • Database driver & version: mysql
  • cannot get into admin to get plugin versions because of issue above
@mattgrayisok

This comment has been minimized.

Copy link

@mattgrayisok mattgrayisok commented Dec 2, 2019

TL;DR For anyone else experiencing this issue the quick fix is to execute delete from [prefix]info where id > 1 against your database. This has worked for me thus far without breaking anything but obviously do a database backup first.


I'm seeing this a lot recently too. It seems to be caused by the activation of maintenance mode:

[-][-][-][error][yii\db\IntegrityException] PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY' in /var/www/html/vendor/yiisoft/yii2/db/Command.php:1290
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1290): PDOStatement->execute()
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1091): yii\db\Command->internalExecute('UPDATE `craft_i...')
#2 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(716): yii\db\Command->execute()
#3 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(1421): craft\web\Application->saveInfo(Object(craft\models\Info))
#4 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(554): craft\web\Application->_setMaintenanceMode(true)
#5 /var/www/html/vendor/craftcms/cms/src/controllers/UpdaterController.php(309): craft\web\Application->enableMaintenanceMode()
#6 /var/www/html/vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(304): craft\controllers\UpdaterController->initialState(false)
#7 /var/www/html/vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(106): craft\controllers\BaseUpdaterController->realInitialState()
#8 [internal function]: craft\controllers\BaseUpdaterController->actionIndex()

An update to the info table is being applied to all rows and the update contains a specific id:

$this->getDb()->createCommand()

But I currently have 5 rows in my info table so it craps out.

I can send over a dump of an example info table that's causing the problem if that helps.

brandonkelly added a commit that referenced this issue Dec 3, 2019
@brandonkelly

This comment has been minimized.

Copy link
Member

@brandonkelly brandonkelly commented Dec 3, 2019

But I currently have 5 rows in my info table so it craps out.

Well that’s the real issue here – not sure how that would have happened. I’ve just made a change that will prevent this from happening. I am a little worried that it will lead to issues for anyone with multiple info rows in the first place though, since there’s no way to know for sure which of those rows Craft will use from request to request, so I have made it on the 3.4 branch.

@mdunbavan

This comment has been minimized.

Copy link
Author

@mdunbavan mdunbavan commented Dec 3, 2019

I suppose it would be good if there was a check or something that flagged an issue beforehand? Like a warning or something as a prompt because it is too late to get that info when you've already completed the migration. Is there anything that checks it with project config sync that could help at all?

@brandonkelly

This comment has been minimized.

Copy link
Member

@brandonkelly brandonkelly commented Dec 3, 2019

There is a check, which is why I’m a little stumped.

@mattgrayisok

This comment has been minimized.

Copy link

@mattgrayisok mattgrayisok commented Dec 3, 2019

FWIW I have a row which looks normal with id 1 and the rest of the rows look like this:

(2,'3.2.10','3.2.16',0,'','','000000000000','2019-09-03 11:02:39','2019-09-03 11:02:39','0e101e0f-3109-4a95-a08f-4480b59af167'),

(3,'3.2.10','3.2.16',0,'','','000000000000','2019-10-31 16:06:19','2019-10-31 16:06:19','520ee405-8269-4025-97eb-facca51f15d6'),

(4,'3.2.10','3.2.16',0,'','','000000000000','2019-10-31 22:08:54','2019-10-31 22:08:54','a91d7ac9-2113-4374-9030-5736f03e3116'),

(5,'3.2.10','3.2.16',0,'','','000000000000','2019-11-10 18:26:18','2019-11-10 18:26:18','a8edd925-1608-42b0-8510-843b37e6858e');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.