﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
5662	get_or_create fails when there is a unique field and other values	kenneth gonsalves <lawgon@…>	nobody	"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? "		closed	Database layer (models, ORM)	dev		invalid	get_or_create		Unreviewed	0	0	0	0	0	0
