Update Asset Index SQL Error 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-&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
---
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:


Someone manually editing database values.
A botched import/export script when backing up/restoring databases.
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.