Saturday, May 11, 2013

Re: Is unique_together case-insensitive ?

What's your database engine?
As i know, if your  database engine was  mysql, and the database's COLLATE pattern name ends with "_ci" which means case-insensitive. you should got that result. 
You can change the COLLATE pattern to the name which ends with "_cs" or "_bin".
Wish it's useful to you



2013/5/11 Parin Porecha <parinporecha@gmail.com>
UPDATE:

On changing the user, it gets saved successfully.
So, the problem is with the object.name

I want to save both the objects. How can I do so ?


On Sat, May 11, 2013 at 12:48 PM, Parin Porecha <parinporecha@gmail.com> wrote:
Hi,

This is my model -

class Tag(models.Model):
    user = models.ForeignKey(get_user_model())
    name = models.CharField(max_length = 300)
    color = models.CharField(max_length = 10)
    icon = models.CharField(max_length = 50)
    
    class Meta:
        unique_together = ("user", "name")
    
    def __unicode__(self, ):
        return self.name

The problem I am facing is -
I made 2 Tag objects =
1) Tag(user = jon, name = 'man')
2) Tag(user = jon, name = 'Man')

The first gets saved, but while saving the second, I am getting the error -
IntegrityError: (1062, "Duplicate entry '2-Man' for key 'user_id'")

I deleted the database, created it again and ran 'syncdb'. Still, I am getting the same error. Is this because of unique_together ?
How can I bypass this ?

Thanks,
Parin


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate