Fixes for database autoupgrade/automigrate bug