Opened 16 years ago
Closed 16 years ago
#11429 closed (duplicate)
initial_data in syncdb not working with proxy models
| Reported by: | Anssi Kääriäinen | Owned by: | nobody | 
|---|---|---|---|
| Component: | Uncategorized | Version: | dev | 
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
I have the following in testapp/models.py:
class Test(models.Model):
    field1 = models.CharField(max_length=20)
class TestProxy(Test):
    class Meta:
        proxy = True
The problem is the proxy model will cause loss of the field1 value when running dumpdata & syncdb. This is best demonstrated by running python manage.py shell and following commands:
from testapp.models import Test t1 = Test(field1='foo') t1.save() t1 = TestExtending.objects.all()[0] t1.field1 Out: u'foo'
All good so far. Now when I run 
python manage.py dumpdata testapp > initial_data.json 
and then 
python manage.py syncdb
and then in python manage.py shell:
from testapp.models import Test t1 = Test.objects.get() t1.field1 Out: u''
The problem is the Test instance is serialized twice to the initial_data.json, once for the Test model with correct field1 value, and once for the TestProxy without any values. Here is the json ouput:
[{"pk": 1, "model": "testapp.test", "fields": {"field1": "foo"}}, {"pk": 1, "model": "testapp.testproxy", "fields": {}}]
I am using Django version 1.1 beta 1 SVN-11196
This is fixed in #11428.