[Fixed]-Why are my model restrictions ignored?

1πŸ‘

βœ…

  1. The empty value of a CharField is the empty string ''.

  2. You do not actually set the code field. What your are actually doing is setting the id.

    >>> co = Code("1234567891011")
    >>> co.id
    "1234567891011"
    

    Try:

    co = Code(code="1234567891011")
    co.save()
    

    or, if you really do not want to use keyword arguments:

    co = Code(None, "1234567891011")
    

    It will raise an exception if you use a database that enforces length constraints (some databases, e.g. SQLite, don’t).

πŸ‘€Daniel Hepper

Leave a comment