0

While using the command in CLI, for migrating my Models created in Django

python manage.py migrate

The CLI Shows an error

__init__() missing 1 required positional argument: 'on_delete'

This is the code:

from django.db import models

class Topic(models.Model):

    top_name = models.CharField(max_length=264,unique=True)

    def __str__(self):
        return self.top_name

class Webpage(models.Model):

    topic = models.ForeignKey(Topic)
    name = models.CharField(max_length=264,unique=True)
    url = models.URLField(unique=True)

    def __str__(self):
        return self.name

class AccessRecord(models.Model):

    name = models.ForeignKey(Webpage)
    date = models.DateField()

    def __str__(self):
        return str(self.date) 
Andronicus
  • 25,419
  • 17
  • 47
  • 88
  • 1
    Possible duplicate of [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) – Ahtisham Feb 02 '19 at 13:28

1 Answers1

1

Because missing 1 required positional argument: 'on_delete' in this line.

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

Django

"A many-to-one relationship. Requires two positional arguments: the class to which the model is related and the on_delete option."

For further details Django Documentation