Answer the question
In order to leave comments, you need to log in
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)
$ ./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;
Answer the question
In order to leave comments, you need to log in
You don’t need to want
this. There is no profit from this, but hemorrhoids are a lot
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question