簡體   English   中英

在 Django model 中進行遷移時出現“外鍵不匹配”錯誤

[英]Getting 'foreign key mismatch' error when making migrations in Django model

我有一個 model 游戲(我正在定義 PK 字段,因為我通過帶有 gameID 的 API 調用填充此表):

class Game(models.Model):
    gameId          = models.IntegerField(primary_key=True, default=-1)
    season          = models.PositiveIntegerField()
    season_type     = models.CharField(max_length=50)
    dateTime        = models.DateTimeField(auto_now_add=True)
    ...
    ...

和 model GameOdd 如下:

class GameOdd(models.Model):
    game                     = models.ForeignKey(Game, on_delete=models.CASCADE)
    sportsbook               = models.CharField(max_length=75)
    created_when             = models.DateTimeField(auto_now_add=True)
    ...
    ...

錯誤消息顯示“外鍵不匹配 - “bets_gameodd”引用“bets_game””(bets 是應用程序的名稱)。 我使用的是 sqlite 數據庫,它是空的(除了我的管理員用戶配置文件)。 這似乎是一個相對簡單的外鍵關系,我先定義父表。 我很困惑為什么我會收到這個錯誤。 有任何想法嗎?

https://community.simpleisbetterthancomplex.com/t/foreign-key-mismatch-error/143

據此,刪除所有遷移文件和 SQLite 文件,然后再次運行python manange.py makemigrations

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM