Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve the "CASCADE() missing required positional arguments" TypeError

Tags:

python

django

I am new to Django and Python. I have created some models in Django, and now can no longer run the application because of the following error:

"TypeError: CASCADE() missing 4 required positional arguments: 'collector', 'field', 'sub_objs', and 'using'"

Here is the model code:

class Lifter(models.Model):
    name = models.CharField(max_length=250)
    age = models.IntegerField(max_length=100);
    gender = models.CharField(max_length=1);
    person_photo = models.CharField(max_length=1000);

def __str__(self):
    return self.name + ' - ' + self.gender

class Results(models.Model):
    lifter = models.ForeignKey(Lifter, on_delete=models.CASCADE())

Any idea on what is wrong?

Thank you!

like image 628
Nora Avatar asked Sep 19 '17 11:09

Nora


1 Answers

Just replace CASCADE() with CASCADE:

class Results(models.Model):
    lifter = models.ForeignKey(Lifter, on_delete=models.CASCADE)

Example with ForeignKey from Django docs

like image 191
Thaian Avatar answered Sep 29 '22 23:09

Thaian