<p>That error indicates a problem with the data in your database.</p>

<p>The <code>craft_assetfolders</code> table has a <code>parentId</code> column that is a foreign key reference to its own <code>id</code> column.  For whatever reason, that <code>parentId</code> column has a value that doesn't exist in any of the <code>id</code> columns, hence your errors.</p>

<p>Some common causes include:</p>

<ol>
<li><p>Someone manually editing database values.</p></li>
<li><p>A botched import/export script when backing up/restoring databases.</p></li>
<li><p>Having multiple Craft installs (maybe across environments) pointing to the same cloud based Asset source (S3, Google Cloud, etc.) and someone deletes/moves/etc. an Asset on one environment making the other one out of sync with reality.</p></li>
</ol>

CC BY-SA 3.0
2017-01-03T11:16:19.747Z
I really appreciate the response. I did some tinkering in the craft_assetfolders table and fond some odd entries. I also disabled plugins that are supposed to help with import/exports, but it ended up being more trouble than it helped. Your advice helped out a lot!
vcao
CC BY-SA 3.0
2017-01-02T01:43:23.270Z
2017-01-02T01:43:23.270Z
Brad Bell
<p>I understand there's a lot of work being done on the Update Asset Indexes feature. I believe I've run into another issue related to MySQL, whereas other issues have been related to PHP's memory_limit. </p>

<p>Would appreciate some feedback on trying to address this issue.</p>

<p>Thanks!</p>

<pre><code>2016/12/31 22:45:19 [error] [system.db.CDbCommand] CDbCommand::execute() failed: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`homeaidoc`.`craft_assetfolders`, CONSTRAINT `craft_assetfolders_parentId_fk` FOREIGN KEY (`parentId`) REFERENCES `craft_assetfolders` (`id`) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO `craft_assetfolders` (`uid`, `parentId`, `sourceId`, `name`, `path`, `dateUpdated`, `dateCreated`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6).
2016/12/31 22:45:19 [error] [exception.CDbException] CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`homeaidoc`.`craft_assetfolders`, CONSTRAINT `craft_assetfolders_parentId_fk` FOREIGN KEY (`parentId`) REFERENCES `craft_assetfolders` (`id`) ON DELETE CASCADE) in /var/www/craft/app/framework/db/CDbCommand.php:358
Stack trace:
#0 /var/www/craft/app/framework/db/ar/CActiveRecord.php(1081): CDbCommand-&gt;execute()
#1 /var/www/craft/app/framework/db/ar/CActiveRecord.php(810): CActiveRecord-&gt;insert(NULL)
#2 /var/www/craft/app/services/AssetsService.php(263): CActiveRecord-&gt;save()
#3 /var/www/craft/app/assetsourcetypes/BaseAssetSourceType.php(1022): Craft\AssetsService-&gt;storeFolder(Object(Craft\AssetFolderModel))
#4 /var/www/craft/app/assetsourcetypes/LocalAssetSourceType.php(121): Craft\BaseAssetSourceType-&gt;ensureFolderByFullPath('development/emm...')
#5 /var/www/craft/app/services/AssetIndexingService.php(40): Craft\LocalAssetSourceType-&gt;startIndex('cf59adea-fe2b-4...')
#6 /var/www/craft/app/tools/AssetIndexTool.php(94): Craft\AssetIndexingService-&gt;getIndexListForSource('cf59adea-fe2b-4...', '1')
#7 /var/www/craft/app/controllers/ToolsController.php(50): Craft\AssetIndexTool-&gt;performAction(Array)
#8 /var/www/craft/app/framework/web/actions/CInlineAction.php(49): Craft\ToolsController-&gt;actionPerformAction()
#9 /var/www/craft/app/framework/web/CController.php(308): CInlineAction-&gt;runWithParams(Array)
#10 /var/www/craft/app/framework/web/CController.php(286): CController-&gt;runAction(Object(CInlineAction))
#11 /var/www/craft/app/framework/web/CController.php(265): CController-&gt;runActionWithFilters(Object(CInlineAction), Array)
#12 /var/www/craft/app/framework/web/CWebApplication.php(282): CController-&gt;run('performAction')
#13 /var/www/craft/app/etc/web/WebApp.php(817): CWebApplication-&gt;runController('tools/performAc...')
#14 /var/www/craft/app/etc/web/WebApp.php(287): Craft\WebApp-&gt;_processActionRequest()
#15 /var/www/craft/app/framework/base/CApplication.php(185): Craft\WebApp-&gt;processRequest()
#16 /var/www/craft/app/index.php(62): CApplication-&gt;run()
#17 /var/www/public/index.php(19): require_once('/var/www/craft/...')
#18 {main}
REQUEST_URI=/index.php/admin/actions/tools/performAction
HTTP_REFERER=http://homeaidoc.craft.dev/admin/settings
---
</code></pre>

<assets><index>
Update Asset Index SQL Error
# Update Asset Index SQL Error

(Asked by: username_0 on 2016-12-31)

I understand there's a lot of work being done on the Update Asset Indexes feature. I believe I've run into another issue related to MySQL, whereas other issues have been related to PHP's memory_limit. 
Would appreciate some feedback on trying to address this issue.
Thanks!
2016/12/31 22:45:19 [error] [system.db.CDbCommand] CDbCommand::execute() failed: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`homeaidoc`.`craft_assetfolders`, CONSTRAINT `craft_assetfolders_parentId_fk` FOREIGN KEY (`parentId`) REFERENCES `craft_assetfolders` (`id`) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO `craft_assetfolders` (`uid`, `parentId`, `sourceId`, `name`, `path`, `dateUpdated`, `dateCreated`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6).
2016/12/31 22:45:19 [error] [exception.CDbException] CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`homeaidoc`.`craft_assetfolders`, CONSTRAINT `craft_assetfolders_parentId_fk` FOREIGN KEY (`parentId`) REFERENCES `craft_assetfolders` (`id`) ON DELETE CASCADE) in /var/www/craft/app/framework/db/CDbCommand.php:358
Stack trace:
#0 /var/www/craft/app/framework/db/ar/CActiveRecord.php(1081): CDbCommand->execute()
#1 /var/www/craft/app/framework/db/ar/CActiveRecord.php(810): CActiveRecord->insert(NULL)
#2 /var/www/craft/app/services/AssetsService.php(263): CActiveRecord->save()
#3 /var/www/craft/app/assetsourcetypes/BaseAssetSourceType.php(1022): Craft\AssetsService->storeFolder(Object(Craft\AssetFolderModel))
#4 /var/www/craft/app/assetsourcetypes/LocalAssetSourceType.php(121): Craft\BaseAssetSourceType->ensureFolderByFullPath('development/emm...')
#5 /var/www/craft/app/services/AssetIndexingService.php(40): Craft\LocalAssetSourceType->startIndex('cf59adea-fe2b-4...')
#6 /var/www/craft/app/tools/AssetIndexTool.php(94): Craft\AssetIndexingService->getIndexListForSource('cf59adea-fe2b-4...', '1')
#7 /var/www/craft/app/controllers/ToolsController.php(50): Craft\AssetIndexTool->performAction(Array)
#8 /var/www/craft/app/framework/web/actions/CInlineAction.php(49): Craft\ToolsController->actionPerformAction()
#9 /var/www/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
#10 /var/www/craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
#11 /var/www/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#12 /var/www/craft/app/framework/web/CWebApplication.php(282): CController->run('performAction')
#13 /var/www/craft/app/etc/web/WebApp.php(817): CWebApplication->runController('tools/performAc...')
#14 /var/www/craft/app/etc/web/WebApp.php(287): Craft\WebApp->_processActionRequest()
#15 /var/www/craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#16 /var/www/craft/app/index.php(62): CApplication->run()
#17 /var/www/public/index.php(19): require_once('/var/www/craft/...')
#18 {main}
REQUEST_URI=/index.php/admin/actions/tools/performAction
HTTP_REFERER=http://homeaidoc.craft.dev/admin/settings
---

**Tags:** assets, index


---

## 1 answers

### Answer by username_1 on 2017-01-02. Score: 1 | Accepted answer

That error indicates a problem with the data in your database.

The `craft_assetfolders` table has a `parentId` column that is a foreign key reference to its own `id` column. For whatever reason, that `parentId` column has a value that doesn't exist in any of the `id` columns, hence your errors.

Some common causes include:

1. Someone manually editing database values.
2. A botched import/export script when backing up/restoring databases.
3. Having multiple Craft installs (maybe across environments) pointing to the same cloud based Asset source (S3, Google Cloud, etc.) and someone deletes/moves/etc. an Asset on one environment making the other one out of sync with reality.

> **Comments:**
> **username_0**: I really appreciate the response. I did some tinkering in the craft_assetfolders table and fond some odd entries. I also disabled plugins that are supposed to help with import/exports, but it ended up being more trouble than it helped. Your advice helped out a lot!  

---

