1π
β
-
The empty value of a CharField is the empty string
''
. -
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
Source:stackexchange.com