Django: TypeError: 'x' is an invalid keyword argument for this function
<p>The view below works, which is utilising the "update_or_create" feature, brilliantly when something exists and therefore updates a record.  However, if it does not exist and has to use the create option to create a new record I get the following error:</p>

<pre><code>TypeError at /selectteams/1025/3/

'soccerseasonid_id' is an invalid keyword argument for this function
</code></pre>

<p>View Below:</p>

<pre><code>if request.method == 'POST':

    form = SelectTwoTeams(request.POST,user=request.user)

    if form.is_valid():

    teamSelection1, created = UserSelection.objects.update_or_create(user_id=currentUserID,
                                     fixturematchday=fixturematchday,
                                     soccerseason_id=soccerseason,
                                     teamselection1or2=1,
                                     defaults={"campaignno":11,
                                           "teamselection1or2":1,
                                           "teamselectionid_id":request.POST['team1'],
                                           "user_id":currentUserID,
                                           "fixturematchday":fixturematchday,
                                           "soccerseasonid_id":soccerseason})

    teamSelection2, created = UserSelection.objects.update_or_create(user_id=currentUserID,
                                     fixturematchday=fixturematchday,
                                     soccerseason_id=soccerseason,
                                     teamselection1or2=2,
                                     defaults={"campaignno":11,
                                           "teamselection1or2":2,
                                           "teamselectionid_id":request.POST['team2'],
                                           "user_id":currentUserID,
                                           "fixturematchday":fixturematchday,
                                           "soccerseasonid_id":soccerseason})
</code></pre>

<p>Models Below:</p>

<pre><code>class StraightredSeason(models.Model):
    seasonid = models.IntegerField(primary_key = True)
    seasonyear = models.CharField(max_length = 4)
    seasonname = models.CharField(max_length = 36)

    def __unicode__(self):
        return self.seasonid

    class Meta:
        managed = True
        db_table = 'straightred_season'

class UserSelection(models.Model):
    userselectionid = models.AutoField(primary_key=True)
    campaignno = models.CharField(max_length=36,unique=False)
    user = models.ForeignKey(User, related_name='selectionUser')
    teamselection1or2 = models.PositiveSmallIntegerField()
    teamselectionid = models.ForeignKey('straightred.StraightredTeam', db_column='teamselectionid', related_name='teamID')
    fixturematchday = models.IntegerField(null=True)
    soccerseason = models.ForeignKey('straightred.StraightredSeason', db_column='soccerseasonid', related_name='fixture_seasonUserSelection')


    class Meta:
        managed = True
        db_table = 'straightred_userselection'
</code></pre>

<p>Any help would be appreciated, many thanks, Alan.</p>

<p>It looks like it is using your defaults where you have "soccerseasonid_id" specified instead of "soccerseason_id". "soccerseason_id" should work.</p>

python mysql django