Ticket #166 (closed defect: invalid)
Default values are not correct
| Reported by: | kencochrane@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | migrations | Version: | 0.5 |
| Keywords: | Cc: |
Description
I'm having an issue with some of my models that have their default field values set as variables instead of strings.
I threw together some pseudo code to show what my issue is.
I reuse default values across multiple fields, and to keep things clean I put them into a common variable, and then use that variable for my defaults. Here is a simple model with a field 'some_field' with a default value of 'SOME_DEFAULT_VALUE' which translates to 'BLAH'
class MyModelExample(models.Model):
SOME_DEFAULT_VALUE = 'BLAH'
some_field = models.CharField(default=SOME_DEFAULT_VALUE, max_length=5)
when I run the "./manage.py startmigration appname --initial" command it produces the migration file with the following (just showing a snippet). Notice that default is set to 'SOME_DEFAULT_VALUE' instead of 'BLAH'
'appname.mymodelexample': {
'some_field': ('models.CharField', [], {'default': 'SOME_DEFAULT_VALUE', 'max_length': '5'}),
},
when I run "./manage.py migrate appname --fake" I get the following error.
ValueError?: Cannot successfully create field 'some_field' for model 'mymodelexample': name 'SOME_DEFAULT_VALUE' is not defined.
If I manually change the default to "BLAH" (example below), it runs through.
'appname.mymodelexample': {
'some_field': ('models.CharField', [], {'default': "'BLAH'", 'max_length': '5'}),
},
I'm using 0.5, and I haven't tried it on SVN trunk yet. Is this a bug, or am I possibly doing something wrong?
Thanks,
Ken

After doing some more searching in trac, I think I found a ticket that already describes this issue. Ticket #128 might fix this, so I will checkout trunk and see if that works for me.