Fixes #1286 SQL error while Upgrade

#1286