Indeed, I'm using optional (and nullable) ForeignKeys in other places as well.
The problem with an optional ForeignKey to Django's contrib sites.Site model, is that it breaks the "View on site" button in the admin section. near line 60 in /django/contrib/contenttypes/views.py: object_domain = getattr(obj, field.name).domain So, is this a bug? Or did I miss something? Dirk On 30 mei 2012, at 15:24, Derek wrote: > Actually, you can have a nullable ForeignKey (and there can be good > reasons for this). This is mentioned in the docs themselves; see: > https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.on_delete > > I am not sure about the error that the OP is encountering. > > > On May 29, 7:47 pm, Thomas Lockhart <tlockhart1...@gmail.com> wrote: >> ...> Hi, >> >>> I have a model which has a ForeignKey to the Django contrib sites.Site >>> model. This field should be optional. >> >> If it is optional it is not a foreign key. You can put a constraint on >> the field to have a non-null value be present in the other table, and >> perhaps there is a way to do this from a django model but I haven't >> looked at that. >> >> hth >> >> - Tom > > -- > 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 > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- ----------------------------- Dirk van Oosterbosch de Wittenstraat 225 1052 AT Amsterdam the Netherlands http://labs.ixopusada.com ----------------------------- -- -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.