Reputation: 1
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)
Upvotes: 0
Views: 292
Reputation: 3748
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
Upvotes: 1