gpt4 book ai didi

python - 参数 'on_delete' 没有值

转载 作者:行者123 更新时间:2023-12-02 00:13:58 25 4
gpt4 key购买 nike

我正在尝试使用 django 运行一些 python 代码,但它返回“构造函数调用中的参数‘on_delete’没有值”。

from django.db import models
from django.contrib.auth.models import User

class Game(models.Model):
first_player = models.ForeignKey(User,
related_name="games_first_player")
second_player = models.ForeignKey(User,
related_name="games_second_player")
start_time = models.DateTimeField(auto_now_add=True)
last_active = models.DateTimeField(auto_now=True)


class Move(models.Model):
x = models.IntegerField()
y = models.IntegerField()
comment = models.CharField(max_length=300, blank=True)
by_first_player = models.BooleanField()


game = models.ForeignKey(Game, on_delete=models.CASCADE)

最佳答案

使用以下代码

from django.db import models
from django.contrib.auth.models import User

class Game(models.Model):
first_player = models.ForeignKey(User,on_delete=models.CASCADE,
related_name="games_first_player")
second_player = models.ForeignKey(User,on_delete=models.CASCADE,
related_name="games_second_player")
start_time = models.DateTimeField(auto_now_add=True)
last_active = models.DateTimeField(auto_now=True)


class Move(models.Model):
x = models.IntegerField()
y = models.IntegerField()
comment = models.CharField(max_length=300, blank=True)
by_first_player = models.BooleanField()

关于python - 参数 'on_delete' 没有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57600935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com