Bugfix/database errors

To be pulled with LLK/scratchr2#1442.