#30210: Allow empty strings of blank=True model fields to pass unique_together
constraint
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  Spleeding1                         |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:             |        Version:  2.1
  Uncategorized                      |       Keywords:  unique_together,
               Severity:  Normal     |  Models
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I've been researching this one a little, and this is what I found:
 [https://stackoverflow.com/questions/454436/unique-fields-that-allow-
 nulls-in-django]

 Here is what I am trying to accomplish:


 {{{
 class MyModel(models.Model):
     my_foreignkey = models.ForeignKey(
         'ForeignKeyModel',
         on_delete=models.CASCADE
     )
     my_charfield = models.CharField(
         'My Field',
         max_length=100,
         blank=True
     )
     field = models.CharField(
         max_length=100
     )

     class Meta:
         unique_together = ('my_foreignkey', 'my_charfield')


 FOREIGN_KEY = ForeignKeyModel.objects.get(id=1)

 MyModel.objects.create(
     my_foreignkey=FOREIGN_KEY,
     field='Field 1',
     my_charfield=''
 )

 # This raises unique_together error.
 MyModel.objects.create(
     my_foreignkey=FOREIGN_KEY,
     field='Field 2',
     my_charfield=''
 )
 }}}

 It does appear as though there is enough interest in the issue. Is this
 unrealistic?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30210>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.641f5083934b6718c2fda8d26bbd3c0e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to