私のmySQLデータベースにサッカーのフィクスチャを引き込むスクリプトがあります。もし私が季節に取り入れようとしなければ、それはうまくいく。しかし、私はそれに休暇を入れて休憩すると、なぜ私は不明です。どんな助けもありがとう。例外値: "x"を割り当てることはできません: "y"は "z"インスタンスでなければなりません
次のようなモデルは次のとおりです。StraightredSeasonテーブルには次のものが含まれ
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'
:
mysql> select * from straightred_season;
+----------+------------+------------+
| seasonid | seasonyear | seasonname |
+----------+------------+------------+
| 1025 | 16/1 | EPL |
+----------+------------+------------+
しかし、私は下のコードを実行するたびに、私は次のエラーを取得する:
は割り当てることができません"1025": "StraightredFixture.soccerseason"は "StraightredSeason"インスタンスでなければなりません。
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)
わかりました:)私は私が使用しているKPIのために1時間に1回しかクエリを実行できないので、まもなくこれを試します。それは指が交差するように論理的なようです。 –