I am new to Django and am trying to write a model to interact with an
existing database. One of the fields in the database has a default
value. To compensate for this, I added default=0 to the Field
declaration. When I went to generate the DDL for the schema to make
sure that I had done everything correctly, I noticed that none of the
fields that I had set default for had DEFAULT 0 as part of their
definition. Is default only used in the admin application? I am
using
the sqlite3 backend.
Here is a model class:
class Survey():
version = models.PositiveIntegerField(default = 0)
id = models.AutoField(db_column = 'survey_id', primary_key = True)
name = models.CharField(max_length = 50, unique = True)
def __unicode__(self):
return '%s <%s>' % self.name, self.id
class Meta:
db_table = 'survey'
Here is the SQL generated for it:
BEGIN;
CREATE TABLE "survey" (
"version" integer unsigned NOT NULL,
"survey_id" integer NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL UNIQUE
)
;
COMMIT;
As you can see, the version field does not have a 'default 0' in it's
definition. Does anyone know what I can do to fix this? I want to be
able to generate the correct schema using manage.py as I will be
moving
to a different DB engine.
Thanks,
Chris Lieb
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---