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

[5.x]: Integrity constraint violation when saving Matrix entry in Solspace Calendar event #16841

Open
jrrdnx opened this issue Mar 6, 2025 · 1 comment
Labels

Comments

@jrrdnx
Copy link

jrrdnx commented Mar 6, 2025

What happened?

Using Matrix fields across multiple sections, including Solspace Calendar events. Adding new entries to a Matrix field works across all sections except Calendar events so I'm not sure if this should be an issue on that repo. However, there's no reference to that package in the stack trace, so trying here first.

This is on a multi-site install as well, so not sure if that is a contributing factor.

2025-03-06 06:45:22 [web.ERROR] [yii\db\IntegrityException] PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`project`.`craft_elementactivity`, CONSTRAINT `craft_fk_fzzzjumymegobofvhctbieacxjdtkwwsowxq` FOREIGN KEY (`elementId`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE) in /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/db/Command.php:1320
Stack trace:
#0 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/db/Command.php(1320): PDOStatement->execute()
#1 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/db/Command.php(1120): yii\db\Command->internalExecute('INSERT INTO `cr...')
#2 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/helpers/Db.php(1084): yii\db\Command->execute()
#3 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/services/Elements.php(2779): craft\helpers\Db::upsert('{{%elementactiv...', Array)
#4 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/controllers/ElementsController.php(1946): craft\services\Elements->trackActivity(Object(craft\elements\Entry), 'save')
#5 [internal function]: craft\controllers\ElementsController->actionApplyDraft()
#6 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#8 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('apply-draft', Array)
#9 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/web/Application.php(361): yii\base\Module->runAction('elements/apply-...', Array)
#10 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/web/Application.php(660): craft\web\Application->runAction('elements/apply-...', Array)
#11 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/web/Application.php(323): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#12 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#13 /Users/username/Repositories/project/craft/web/index.php(15): yii\base\Application->run()
#14 /Applications/Herd.app/Contents/Resources/valet/server.php(167): require('/Users/username...')
#15 {main}

Next yii\db\IntegrityException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`project`.`craft_elementactivity`, CONSTRAINT `craft_fk_fzzzjumymegobofvhctbieacxjdtkwwsowxq` FOREIGN KEY (`elementId`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE)
The SQL being executed was: INSERT INTO `craft_elementactivity` (`elementId`, `userId`, `siteId`, `draftId`, `type`, `timestamp`) VALUES (3798, 1, 1, NULL, 'save', '2025-03-06 11:45:22') ON DUPLICATE KEY UPDATE `siteId`=VALUES(`siteId`), `draftId`=VALUES(`draftId`), `timestamp`=VALUES(`timestamp`) in /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/db/Schema.php:676
Stack trace:
#0 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/db/Command.php(1325): yii\db\Schema->convertException(Object(PDOException), 'INSERT INTO `cr...')
#1 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/db/Command.php(1120): yii\db\Command->internalExecute('INSERT INTO `cr...')
#2 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/helpers/Db.php(1084): yii\db\Command->execute()
#3 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/services/Elements.php(2779): craft\helpers\Db::upsert('{{%elementactiv...', Array)
#4 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/controllers/ElementsController.php(1946): craft\services\Elements->trackActivity(Object(craft\elements\Entry), 'save')
#5 [internal function]: craft\controllers\ElementsController->actionApplyDraft()
#6 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#8 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('apply-draft', Array)
#9 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/web/Application.php(361): yii\base\Module->runAction('elements/apply-...', Array)
#10 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/web/Application.php(660): craft\web\Application->runAction('elements/apply-...', Array)
#11 /Users/username/Repositories/project/craft/vendor/craftcms/cms/src/web/Application.php(323): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#12 /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#13 /Users/username/Repositories/project/craft/web/index.php(15): yii\base\Application->run()
#14 /Applications/Herd.app/Contents/Resources/valet/server.php(167): require('/Users/username...')
#15 {main}
Additional Information:
Array
(
    [0] => 23000
    [1] => 1452
    [2] => Cannot add or update a child row: a foreign key constraint fails (`project`.`craft_elementactivity`, CONSTRAINT `craft_fk_fzzzjumymegobofvhctbieacxjdtkwwsowxq` FOREIGN KEY (`elementId`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE)
)
 {"memory":11996232,"exception":"[object] (yii\\db\\IntegrityException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`project`.`craft_elementactivity`, CONSTRAINT `craft_fk_fzzzjumymegobofvhctbieacxjdtkwwsowxq` FOREIGN KEY (`elementId`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE)
The SQL being executed was: INSERT INTO `craft_elementactivity` (`elementId`, `userId`, `siteId`, `draftId`, `type`, `timestamp`) VALUES (3798, 1, 1, NULL, 'save', '2025-03-06 11:45:22') ON DUPLICATE KEY UPDATE `siteId`=VALUES(`siteId`), `draftId`=VALUES(`draftId`), `timestamp`=VALUES(`timestamp`) at /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/db/Schema.php:676)
[previous exception] [object] (PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`project`.`craft_elementactivity`, CONSTRAINT `craft_fk_fzzzjumymegobofvhctbieacxjdtkwwsowxq` FOREIGN KEY (`elementId`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE) at /Users/username/Repositories/project/craft/vendor/yiisoft/yii2/db/Command.php:1320)"} 

Craft CMS version

5.6.11

PHP version

8.3.17 and 8.3.7

Operating system and version

Darwin 24.3.0 (macOS 15.3.1) and Linux 6.5.0-1020-aws

Database type and version

MySQL 8.0.27 and MySQL 8.0.36

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.1-43)

Installed plugins and versions

  • Blitz 5.9.10
  • Calendar 5.0.15
  • CKEditor 4.6.0
  • Cloudflare R2 1.1.1
  • CP Field Inspect 2.0.4
  • Elements Panel 3.0.1
  • Embedded Assets 5.4.3
  • Feed Me 6.7.0
  • Retour 5.0.8
  • Schedule 0.6.2
  • Sentry Logger 5.0.2
  • SEOmatic 5.1.11
  • Sherlock 5.1.0
  • Vite 5.0.1
@jrrdnx jrrdnx added the bug label Mar 6, 2025
@brandonkelly
Copy link
Member

I’m not able to reproduce that. Tested with all three Matrix view mode options.

Can you send your database and Composer files into [email protected]? We can look into it from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants