#5662: get_or_create fails when there is a unique field and other values
-------------------------------------------------------+--------------------
Reporter:  kenneth gonsalves <[EMAIL PROTECTED]>  |       Owner:  nobody        
  
  Status:  new                                         |   Component:  Database 
wrapper
 Version:  SVN                                         |    Keywords:  
get_or_create   
   Stage:  Unreviewed                                  |   Has_patch:  0        
       
-------------------------------------------------------+--------------------
 This is for svn head and postgresql backend. Assume a model like this:
 {{{
 class Word(models.Model):

     language=models.ForeignKey(Language)
     rootword=models.ForeignKey(Rootword,blank=True,null=True)
     word=models.CharField(_("Word"),maxlength=100,unique=True)
     english=models.CharField(_("English Meaning"),maxlength=500)
 }}}

 I want to dump values from some external source into this table using
 get_or_create. If the 'word' exists, the no action should be taken,
 otherwise the row has to be created. If i make my query like this:
 {{{
 a,b = Word.objects.get_or_create(word=wd, language=lng,rootword=rtwd,
 english=eng)
 }}}
 then unless *all* the fields match in the existing row, django assumes
 that the row does not exist and attempts to create the row which results
 in a duplicate key error in postgresql. As a result, the query has to be
 restricted to 'word' only, to avoid the duplicate key error. If the row
 containing 'word' is got, then the row has to be updated with the
 remaining values. If it is created - again it needs to be updated with the
 remaining values. This could be solved with an update_or_create query?

-- 
Ticket URL: <http://code.djangoproject.com/ticket/5662>
Django Code <http://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 post to this group, send email to django-updates@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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to