Fix SQL error when upgrading from previous version