D
D
Diabo1ic2016-09-19 15:03:31
PostgreSQL
Diabo1ic, 2016-09-19 15:03:31

How to assign default values ​​at the SQL level in Django (PostgreSQL)?

I create a model with default fields, expecting them to be saved at the sql level:

class Car(models.Model):
    name = models.CharField('Name', max_length=255, default='Audi')
    max_speed = models.IntegerField('Max Speed', default=220)

But actually default values ​​are not generated in SQL:
$ ./manage.py sqlmigrate car 0001
BEGIN;
--
-- Create model Car
--
CREATE TABLE "car" ("id" serial NOT NULL PRIMARY KEY, "name" varchar(255) NOT NULL, "max_speed" integer NOT NULL);
COMMIT;

How can I save default values ​​in sql level?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-09-19
@Diabo1ic

You don’t need to want
this. There is no profit from this, but hemorrhoids are a lot

P
Pavel Shvedov, 2016-09-19
@mmmaaak

Add your hands in the migration files

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question