Issue/830/migration fail with custom user model

This pull request fixes issue #830.