Search code examples
pythondjangopostgresqldjango-modelsnumeric

Django model field for PostgreSQL NUMERIC data type


I'm using Django to create an application (using PostgreSQL) that needs a column numeric(15,6), but I'm not finding a method to do this.


Solution

  • From PostgreSQL docs:

    The types decimal and numeric are equivalent. Both types are part of the SQL standard.

    So you can use Django's DecimalField

    class MyModel(models.Model):
        my_field = models.DecimalField(max_digits=15, decimal_places=6)
    

    Some docs: