'A helper for subclasses overriding _alter_add_column_mods:
Add a check constraint verifying positivity to PositiveInteger and
PositiveSmallInteger fields.'

def _alter_add_positive_check(self, klass, field, name, params, sqls):

    super(klass, self)._alter_add_column_mods(field, name, params, sqls)
    if isinstance(field, (models.PositiveSmallIntegerField, models.PositiveIntegerField)):
        uniq_hash = abs(hash(tuple(params.values())))
        d = dict(constraint=('CK_%s_PSTV_%s' % (name, hex(uniq_hash)[2:])), check=('%s    >=    0' % self.quote_name(name)))
        sqls.append(((self.add_check_constraint_fragment % d), []))
