Re: multiple OneToOne fields pointing to the same table

2007-06-26 Thread Malcolm Tredinnick

On Tue, 2007-06-26 at 16:34 +, Charles Wesley wrote:
> I want a model where a single table has two OneToOne fields pointing
> back to another table. Here's the trivial example:
> 
> 
> class Trivial(models.Model):
> pass
> 
> class Multiple(models.Model):
> one_trivial = models.OneToOneField(Trivial,
> related_name="one_trivial")
> two_trivial = models.OneToOneField(Trivial,
> related_name="two_trivial")
> 
> This breaks at syncdb using MySQL (error: 1068, 'Multiple primary key
> defined'). So is this a problem with MySQL or Django? Is my best bet
> to just turn those OneToOneFields into ForeignKeys with
> max_num_in_admin = 1?

At the moment, OneToOneFields in Django are implicitly made into primary
keys, so the constraint is on the Django side. At some point prior to
1.0, this will have to relax a little bit as part of implementing model
inheritance, however, right now that's the state of play. So, yes, if
you want a structure like this, you will have to fake one of the links
with a ForeignKey.

Regards,
Malcolm

-- 
If at first you don't succeed, destroy all evidence that you tried. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



multiple OneToOne fields pointing to the same table

2007-06-26 Thread Charles Wesley

I want a model where a single table has two OneToOne fields pointing
back to another table. Here's the trivial example:


class Trivial(models.Model):
pass

class Multiple(models.Model):
one_trivial = models.OneToOneField(Trivial,
related_name="one_trivial")
two_trivial = models.OneToOneField(Trivial,
related_name="two_trivial")

This breaks at syncdb using MySQL (error: 1068, 'Multiple primary key
defined'). So is this a problem with MySQL or Django? Is my best bet
to just turn those OneToOneFields into ForeignKeys with
max_num_in_admin = 1?

Thanks,
charles


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---