Opened 7 years ago

Closed 7 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: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I have the following in testapp/

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 shell and following commands:

from testapp.models import Test
t1 = Test(field1='foo')
t1 = TestExtending.objects.all()[0]
Out: u'foo'

All good so far. Now when I run

python dumpdata testapp > initial_data.json

and then

python syncdb

and then in python shell:

from testapp.models import Test
t1 = Test.objects.get()
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

Change History (1)

comment:1 Changed 7 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: duplicate
Status: newclosed

This is fixed in #11428.

Note: See TracTickets for help on using tickets.
Back to Top