Various wagtailimages database fixes

This pull request fixes #664 and partly fixes #312