Exception Value: Cannot assign "x": "y" must be a "z" instance
<p>I have a script to pull in football fixtures into my mySQL database.  If I do not try to pull in the seasonid it works.  But when I put the seasonid in it breaks and I am unsure why.  Any help would be appreciated.</p>

<p>The models are as follows:</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 StraightredTeam(models.Model):
    teamid = models.IntegerField(primary_key=True)
    teamname = models.CharField(max_length=36)
    country = models.CharField(max_length=36,null=True)
    stadium = models.CharField(max_length=36,null=True)
    homepageurl = models.TextField(null=True)
    wikilink = models.TextField(null=True)
    teamcode = models.CharField(max_length=5,null=True)
    teamshortname = models.CharField(max_length=24,null=True)
    currentteam = models.PositiveSmallIntegerField(null=True)

    def __unicode__(self):
        return self.teamname

    class Meta:
        managed = True
        db_table = 'straightred_team'

class StraightredFixture(models.Model):
    fixtureid = models.IntegerField(primary_key=True)
    home_team = models.ForeignKey('straightred.StraightredTeam', db_column='hometeamid', related_name='home_fixtures')
    away_team = models.ForeignKey('straightred.StraightredTeam', db_column='awayteamid', related_name='away_fixtures')
    fixturedate = models.DateTimeField(null=True)
    fixturestatus = models.CharField(max_length=24,null=True)
    fixturematchday = models.IntegerField(null=True)
    spectators = models.IntegerField(null=True)
    hometeamscore = models.IntegerField(null=True)
    awayteamscore = models.IntegerField(null=True)
    homegoaldetails = models.TextField(null=True)
    awaygoaldetails = models.TextField(null=True)
    hometeamyellowcarddetails = models.TextField(null=True)
    awayteamyellowcarddetails = models.TextField(null=True)
    hometeamredcarddetails = models.TextField(null=True)
    awayteamredcarddetails = models.TextField(null=True)
    soccerseason = models.ForeignKey('straightred.StraightredSeason', db_column='soccerseasonid', related_name='fixture_season')


    def __unicode__(self):
        return self.fixtureid

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

<p>The StraightredSeason table contains the following:</p>

<pre><code>mysql&gt; select * from straightred_season;
+----------+------------+------------+
| seasonid | seasonyear | seasonname |
+----------+------------+------------+
|     1025 | 16/1       | EPL        |
+----------+------------+------------+
</code></pre>

<p>But whenever I run the code below I get the following error:</p>

<p>Cannot assign "1025": "StraightredFixture.soccerseason" must be a "StraightredSeason" instance.</p>

<pre><code>            fixtureUpdate = StraightredFixture(fixtureid=fixture['Id'],
                                               away_team_id = fixture['AwayTeam_Id'],
                                               home_team_id = fixture['HomeTeam_Id'],
                                               fixturedate = fixture['Date'],
                                               fixturestatus = fixture['Time'],
                                               fixturematchday = fixture['Round'],
                                               spectators = fixture['Spectators'],
                                               hometeamscore = fixture['HomeGoals'],
                                               awayteamscore = fixture['AwayGoals'],
                                               homegoaldetails = fixture['HomeGoalDetails'],
                                               awaygoaldetails = fixture['AwayGoalDetails'],
                                               hometeamyellowcarddetails = fixture['HomeTeamYellowCardDetails'],
                                               awayteamyellowcarddetails = fixture['AwayTeamYellowCardDetails'],
                                               hometeamredcarddetails = fixture['HomeTeamRedCardDetails'],
                                               awayteamredcarddetails = fixture['AwayTeamRedCardDetails'],
                       soccerseason = 1025)
</code></pre>

<p>You can't set a <code>ForeignKey</code> object as <code>int</code>. You can instead set the <code>ForeignKey</code> <em>value</em> (id associated with the FK object) by appending <code>_id</code> to the field:</p>

<pre><code>fixtureUpdate = StraightredFixture(fixtureid=fixture['Id'],
                                   ...
                                   soccerseason_id = 1025)
#                                              ^^^
</code></pre>

python mysql django