I am trying to run some python code, using django, but it is returning that “No value for argument ‘on_delete’ in constructor call”.
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)
Advertisement
Answer
Use Following Code
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()