Using Natural Keys With dumpdata / loaddata

121 views
Skip to first unread message

Alex Thomas

unread,
Jan 23, 2014, 9:03:34 PM1/23/14
to django...@googlegroups.com
I have already created a stackoverflow question on this and have only received one (incorrect) response.  For the sake of time I am just linking that question which has all the details.

http://stackoverflow.com/questions/21151544/django-loaddata-with-natural-keys-not-querying-correct-forign-key


-Alex

Mike Dewhirst

unread,
Jan 24, 2014, 2:18:15 AM1/24/14
to django...@googlegroups.com
On 24/01/2014 8:03am, Alex Thomas wrote:
> I have already created a stackoverflow question on this and have only
> received one (*incorrect*) response. For the sake of time I am just
Is it possible that voyage_id is the problem?

https://docs.djangoproject.com/en/1.6/topics/serialization/#topics-serialization-natural-keys

That documentation says that the natural key must be unique and you need
either unique=True for a single field or a meta attribute of
unique_together nominating those fields you want as the natural keys.

Have you tried unique=True for voyage_id?

If that doesn't work, maybe you can pair it with another value or values
which would be unique together.

Mike


>
>
>
> -Alex
>
> -- You received this message because you are subscribed to the Google
> Groups "Django users" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
> django-users...@googlegroups.com. To post to this group,
> send email to django...@googlegroups.com. Visit this group at
> http://groups.google.com/group/django-users. To view this discussion
> on the web visit
> https://groups.google.com/d/msgid/django-users/8a619cdb-1ac4-474b-8d6e-ef45825c418b%40googlegroups.com.
>
>
For more options, visit https://groups.google.com/groups/opt_out.

Message has been deleted

Alex Thomas

unread,
Jan 24, 2014, 8:31:01 PM1/24/14
to django...@googlegroups.com
I tried adding unique=True to voyage_id but that did not have any effect.  I later found somewhere in the docs that specifying is not necessary.  So I am still in the same situation.

Mike Dewhirst

unread,
Jan 24, 2014, 10:40:09 PM1/24/14
to django...@googlegroups.com
On 25/01/2014 7:31am, Alex Thomas wrote:
> I tried adding unique=True to voyage_id but that did not have any
> effect. I later found somewhere in the docs that specifying is not
> necessary. So I am still in the same situation.

Is it possible to have unique=True together with null=True and blank=True???

In theory that is mutually incompatible. Two records with a blank
voyage_id have the same voyage_id therefore voyage_id is not unique. I'm
not sure but I have a feeling the ORM permits this for normal operations
but it would probably break loaddata.

>
> On Thursday, January 23, 2014 4:03:34 PM UTC-5, Alex Thomas wrote:
>
> I have already created a stackoverflow question on this and have
> only received one (*incorrect*) response. For the sake of time I am
> <http://stackoverflow.com/questions/21151544/django-loaddata-with-natural-keys-not-querying-correct-forign-key>
>
>
> -Alex
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/aa2a7cac-d7fb-4855-a356-5731897dff24%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages