Mansoor Butt
Mansoor Butt

Reputation: 1

How to fix Migrations Error , While migrating My Models

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

Answers (1)

Muhammad Faizan Fareed
Muhammad Faizan Fareed

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

Related Questions