0

I'm getting a typeerror: __init__() missing 1 required positional argument: 'on_delete'

class Topic(models.Model)    
    text=models.CharField(max_length=200)   
    date_added=models.DateTimeField(auto_now_add=True)
class Entry(models.Model):
    topic = models.ForeignKey(Topic)
    text = models.TextField()
    date_added=models.DateTimeField(auto_now_add=True) 
    class Meta:
        verbose_name_plural='entries'
    def __str__(self):
        return self.text[:50] + "..."
Abdul Aziz Barkat
  • 19,475
  • 3
  • 20
  • 33
CodedX
  • 29
  • 1
  • 4
  • Does this answer your question? [Getting TypeError: \_\_init\_\_() missing 1 required positional argument: 'on\_delete' when trying to add parent table after child table with entries](https://stackoverflow.com/questions/44026548/getting-typeerror-init-missing-1-required-positional-argument-on-delete) – Abdul Aziz Barkat May 30 '21 at 16:17

1 Answers1

1

add the on_delete=models.CASCADE in your topic of ForeignKey, like this:

topic = models.ForeignKey(Topic, on_delete=models.CASCADE)

in Django when you us ForeignKey need to add on_delete=models.CASCADE it mean when you delete Topic, in Entry model topic is same will be delete together

Max
  • 836
  • 6
  • 13