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

Integrity constraint violation error after save entry #588

Closed
luizboaretto opened this issue Nov 25, 2023 · 4 comments
Closed

Integrity constraint violation error after save entry #588

luizboaretto opened this issue Nov 25, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@luizboaretto
Copy link

Here is the full error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`db`.`blitz_elementcaches`, CONSTRAINT `fk_xfvcfwkffanlcincrahwwsxihqbbpnmctrbp` FOREIGN KEY (`cacheId`) REFERENCES `blitz_caches` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
#13 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1302): PDOStatement::execute
#12 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1302): yii\db\Command::internalExecute
#11 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command::execute
#10 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php(710): putyourlightson\blitz\services\GenerateCacheService::_batchInsertCaches
#9 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php(651): putyourlightson\blitz\services\GenerateCacheService::_batchInsertElementCaches
#8 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php(496): putyourlightson\blitz\services\GenerateCacheService::save
#7 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/CacheRequestService.php(502): putyourlightson\blitz\services\CacheRequestService::saveAndPrepareResponse
#6 /var/www/html/vendor/putyourlightson/craft-blitz/src/Blitz.php(327): putyourlightson\blitz\Blitz::putyourlightson\blitz\{closure}
#5 [internal](0): call_user_func
#4 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): yii\base\Event::trigger
#3 /var/www/html/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Component::trigger
#2 /var/www/html/vendor/yiisoft/yii2/web/Response.php(341): yii\web\Response::send
#1 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\base\Application::run
#0 /index.php(12): null

yii\db\IntegrityException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`db`.`blitz_elementcaches`, CONSTRAINT `fk_xfvcfwkffanlcincrahwwsxihqbbpnmctrbp` FOREIGN KEY (`cacheId`) REFERENCES `blitz_caches` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
The SQL being executed was: INSERT INTO `blitz_elementcaches` (`cacheId`, `elementId`) VALUES (161, 5), (161, 39)
#13 /var/www/html/vendor/yiisoft/yii2/db/Schema.php(676): yii\db\Schema::convertException
#12 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Command::internalExecute
#11 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command::execute
#10 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php(710): putyourlightson\blitz\services\GenerateCacheService::_batchInsertCaches
#9 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php(651): putyourlightson\blitz\services\GenerateCacheService::_batchInsertElementCaches
#8 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php(496): putyourlightson\blitz\services\GenerateCacheService::save
#7 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/CacheRequestService.php(502): putyourlightson\blitz\services\CacheRequestService::saveAndPrepareResponse
#6 /var/www/html/vendor/putyourlightson/craft-blitz/src/Blitz.php(327): putyourlightson\blitz\Blitz::putyourlightson\blitz\{closure}
#5 [internal](0): call_user_func
#4 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): yii\base\Event::trigger
#3 /var/www/html/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Component::trigger
#2 /var/www/html/vendor/yiisoft/yii2/web/Response.php(341): yii\web\Response::send
#1 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\base\Application::run
#0 /index.php(12): null
  • Craft 4.5.11.1
  • Blitz 4.9.1
  • MySQL 8.0.33
  • PHP 8.2.11
@luizboaretto luizboaretto added the bug Something isn't working label Nov 25, 2023
@bencroker
Copy link
Collaborator

Was this a one-off error or is this something you can reproduce?

@luizboaretto
Copy link
Author

luizboaretto commented Nov 26, 2023

Was this a one-off error or is this something you can reproduce?

This happened twice. I received this at Sentry. It didn't appear when I updated the entries (inside CP). I've done some testing now and haven't gotten these errors again...🤷‍♂️

@bencroker
Copy link
Collaborator

That makes sense. We us a mutex to prevent those issues as much as possible but every now and then they crop up. I’ve moved the database command into a try/catch block in 39b83fb to prevent this from occurring in future.

@bencroker
Copy link
Collaborator

Released in 4.9.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants