Fix SQL error in model