1.Text and numeric field types
CharField requires max_length (a bounded string); TextField has none (unbounded). Integer/BigInteger/PositiveInteger differ only in range. DecimalField (max_digits + decimal_places, fixed precision) is for money; FloatField (native float, imprecise) is not.
Key features
- CharField(max_length=N) is required — an unbounded VARCHAR is a TextField, not a CharField with no max_length
- TextField has no enforced length limit at the database or model level
- IntegerField holds roughly ±2.1 billion; BigIntegerField roughly ±9.2 quintillion; PositiveIntegerField is 0 to ~2.1 billion
- DecimalField(max_digits=10, decimal_places=2) stores an exact Decimal — always the right choice for money
- FloatField stores a native Python float — fine for scientific/measurement data, wrong for anything requiring exact arithmetic
Text and numeric fields at a glance
- Decimal("0.1") + Decimal("0.2") — Decimal('0.3') — exact
- 0.1 + 0.2 (float) — 0.30000000000000004 — not exact
Command
price = models.DecimalField(max_digits=10, decimal_places=2)
# max_digits=10, decimal_places=2 -> up to 99999999.99DecimalField (exact, max_digits+decimal_places) for money; FloatField (binary, imprecise) never for money. CharField requires max_length; TextField has none.