Integrity Constraint Violation error in 3.4 beta
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
Description
I've just dragged an old field into an old entry's field setup in the Admin and it's thrown this error:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'shortDesc-global' for key 'fields_handle_context_unq_idx' in /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/Command.php:1290
Stack trace:
#0 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/Command.php(1290): PDOStatement->execute()
#1 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/Command.php(1091): yii\db\Command->internalExecute('INSERT INTO `fi...')
#2 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/Schema.php(432): yii\db\Command->execute()
#3 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/ActiveRecord.php(600): yii\db\Schema->insert('{{%fields}}', Array)
#4 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/ActiveRecord.php(566): yii\db\ActiveRecord->insertInternal(NULL)
#5 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/BaseActiveRecord.php(678): yii\db\ActiveRecord->insert(false, NULL)
#6 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/Fields.php(1545): yii\db\BaseActiveRecord->save(false)
#7 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/Fields.php(836): craft\services\Fields->applyFieldSave('e2a31a80-4266-4...', Array, 'global')
#8 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(945): craft\services\Fields->handleChangedField(Object(craft\events\ConfigEvent))
#9 [internal function]: craft\services\ProjectConfig->craft\services\{closure}(Object(craft\events\ConfigEvent))
#10 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Object(Closure), Object(craft\events\ConfigEvent))
#11 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(584): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#12 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/helpers/ProjectConfig.php(64): craft\services\ProjectConfig->processConfigChanges('fields.e2a31a80...')
#13 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/Sections.php(1184): craft\helpers\ProjectConfig::ensureAllFieldsProcessed()
#14 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(945): craft\services\Sections->handleChangedEntryType(Object(craft\events\ConfigEvent))
#15 [internal function]: craft\services\ProjectConfig->craft\services\{closure}(Object(craft\events\ConfigEvent))
#16 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Object(Closure), Object(craft\events\ConfigEvent))
#17 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(592): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#18 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(427): craft\services\ProjectConfig->processConfigChanges('sections.4e9673...', true, 'Save entry type...')
#19 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/Sections.php(1163): craft\services\ProjectConfig->set('sections.4e9673...', Array, 'Save entry type...')
#20 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/controllers/SectionsController.php(374): craft\services\Sections->saveEntryType(Object(craft\models\EntryType))
#21 [internal function]: craft\controllers\SectionsController->actionSaveEntryType()
#22 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#23 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#24 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('save-entry-type', Array)
#25 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-entry-type', Array)
#26 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('sections/save-e...', Array)
#27 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/web/Application.php(565): craft\web\Application->runAction('sections/save-e...', Array)
#28 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#29 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#30 /Users/jaycollett/Sites/jaycollett/mama-codes/build/public/index.php(21): yii\base\Application->run()
#31 {main}
Next yii\db\IntegrityException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'shortDesc-global' for key 'fields_handle_context_unq_idx'
The SQL being executed was: INSERT INTO `fields` (`uid`, `groupId`, `name`, `handle`, `context`, `instructions`, `searchable`, `translationMethod`, `translationKeyFormat`, `type`, `settings`, `dateCreated`, `dateUpdated`) VALUES ('e2a31a80-4266-4c5f-a72d-cf3990e795cb', 5, 'Short description', 'shortDesc', 'global', '', 1, 'none', NULL, 'craft\\fields\\PlainText', '{\"byteLimit\":null,\"charLimit\":null,\"code\":\"\",\"columnType\":null,\"initialRows\":\"4\",\"multiline\":\"\",\"placeholder\":\"\"}', '2019-12-18 15:42:38', '2019-12-18 15:42:38') in /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/Schema.php:674
Stack trace:
#0 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/Command.php(1295): yii\db\Schema->convertException(Object(PDOException), 'INSERT INTO `fi...')
#1 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/Command.php(1091): yii\db\Command->internalExecute('INSERT INTO `fi...')
#2 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/Schema.php(432): yii\db\Command->execute()
#3 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/ActiveRecord.php(600): yii\db\Schema->insert('{{%fields}}', Array)
#4 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/ActiveRecord.php(566): yii\db\ActiveRecord->insertInternal(NULL)
#5 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/db/BaseActiveRecord.php(678): yii\db\ActiveRecord->insert(false, NULL)
#6 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/Fields.php(1545): yii\db\BaseActiveRecord->save(false)
#7 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/Fields.php(836): craft\services\Fields->applyFieldSave('e2a31a80-4266-4...', Array, 'global')
#8 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(945): craft\services\Fields->handleChangedField(Object(craft\events\ConfigEvent))
#9 [internal function]: craft\services\ProjectConfig->craft\services\{closure}(Object(craft\events\ConfigEvent))
#10 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Object(Closure), Object(craft\events\ConfigEvent))
#11 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(584): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#12 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/helpers/ProjectConfig.php(64): craft\services\ProjectConfig->processConfigChanges('fields.e2a31a80...')
#13 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/Sections.php(1184): craft\helpers\ProjectConfig::ensureAllFieldsProcessed()
#14 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(945): craft\services\Sections->handleChangedEntryType(Object(craft\events\ConfigEvent))
#15 [internal function]: craft\services\ProjectConfig->craft\services\{closure}(Object(craft\events\ConfigEvent))
#16 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Object(Closure), Object(craft\events\ConfigEvent))
#17 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(592): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#18 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/ProjectConfig.php(427): craft\services\ProjectConfig->processConfigChanges('sections.4e9673...', true, 'Save entry type...')
#19 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/services/Sections.php(1163): craft\services\ProjectConfig->set('sections.4e9673...', Array, 'Save entry type...')
#20 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/controllers/SectionsController.php(374): craft\services\Sections->saveEntryType(Object(craft\models\EntryType))
#21 [internal function]: craft\controllers\SectionsController->actionSaveEntryType()
#22 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#23 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#24 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('save-entry-type', Array)
#25 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-entry-type', Array)
#26 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('sections/save-e...', Array)
#27 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/web/Application.php(565): craft\web\Application->runAction('sections/save-e...', Array)
#28 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#29 /Users/jaycollett/Sites/jaycollett/mama-codes/build/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#30 /Users/jaycollett/Sites/jaycollett/mama-codes/build/public/index.php(21): yii\base\Application->run()
#31 {main}
Additional Information:
Array
(
[0] => 23000
[1] => 1062
[2] => Duplicate entry 'shortDesc-global' for key 'fields_handle_context_unq_idx'
)
It's mentioning the shortDesc field which is odd, because that field isn't one that I was adjusting.
I can provide more details if required.
Steps to reproduce
- Not sure tbh but I was dragging a field into an entry field config.
Additional info
- Craft version: 3.4.0-beta.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with craft/services/Fields.php, especially applyFieldSave(), and trace the save flow through craft/services/ProjectConfig.php, craft/services/Sections.php, and SectionsController.php. Reproduce the Admin field-dragging scenario if possible and determine why an existing shortDesc/global field is inserted again; done means the operation completes without the duplicate-key error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100