Reputation: 5057
I have added a new field to my model to track the individual objects to users.
I then generated a migration using south and it asked me for a default value for this migration as the user field has no default value. I entered 1 as the id of the user. I am using sqlite as the db backend for development. Now when I open an sqlite shell and look at the db schema, the default value is still there:
CREATE TABLE "base_category" ("user_id" integer NOT NULL DEFAULT 1,
"id" integer PRIMARY KEY,
"name" varchar(80) NOT NULL);
However in the migration file it looks like this:
# Adding field 'TimeSlot.user'
db.add_column('base_timeslot', 'user',
self.gf('django.db.models.fields.related.ForeignKey')
(default=1, to=orm['auth.User']),
keep_default=False)
If I understood the south docs correctly, it should not be there:
If
keep_default
is True, then any default value specified on the field will be added to the database schema for that column permanently. If not, then the default is only used when adding the column, and then dropped afterwards.
In other questions here on SO it was pointed out, that the default values are not handled on a db level, but in python instead.
finally my questions:
Upvotes: 1
Views: 967
Reputation: 3083
It wasn't considered a bug, but is now; South 0.7.7 (forthcoming as I write this) should fix it.
Upvotes: 2
Reputation: 320
Do not worry, the DEFAULT 1
in the DB only specifies that if you create a new instance in the table, this field will be populated with 1 by default, but this value can be changed. What keep_default
does is disabling the value from being edited, e.g. a new field will get value 1 as default and you can't change the value. This is not your case. You will get default value 1 on new instances but you will be able to edit the value.
Continuing point num 1 - no need to remove the value since DEFAULT 1
is the correct representation of a default value for a new instance of a field.
Upvotes: 0