Friday, March 11, 2016

Workaround for trouble with updating akonadi tables

I was just updating the Kubuntu packages that move from akonadi 15.08 to 15.12.1 and sadly akonadi failed to migrate with this error


Adding new foreign key constraints
"ALTER TABLE PimItemFlagRelation ADD FOREIGN KEY (PimItem_id) REFERENCES PimItemTable(id) ON UPDATE CASCADE ON DELETE CASCADE"
Updating index failed:
Sql error: Cannot add or update a child row: a foreign key constraint fails (`akonadi`.`#sql-6ea8_3`, CONSTRAINT `#sql-6ea8_3_ibfk_1` FOREIGN KEY (`PimItem_id`) REFERENCES `pimitemtable` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) QMYSQL: Unable to execute query
Query: ALTER TABLE PimItemFlagRelation ADD FOREIGN KEY (PimItem_id) REFERENCES PimItemTable(id) ON UPDATE CASCADE ON DELETE CASCADE
""
Unable to initialize database.

Bug 354536 will be fixed with the akonadi 15.12.3 release next week.

Lucky meanwhile amazing Dan was ready to help me workaround the issue.

You need to start mysql (if that's what you're using as akonadi backend)
mysqld --defaults-file=$HOME/.local/share/akonadi/mysql.conf --datadir=$HOME/.local/share/akonadi/db_data --socket=/tmp/akonadi-mysql.socket

then connect to it
mysql -S /tmp/akonadi-mysql.socket

And run a series of sql commands
http://paste.ubuntu.com/15344766/

After that shut down mysql
mysqladmin -S /tmp/akonadi-mysql.socket shutdown

And start akonadi and you should be golden again
akonadictrl start