logo
  • Python
  • Django
  • Tools
    • Email Extractor Tool Free Online
    • Calculate Text Read Time Online
    • HTML to Markdown Converter Online
    • Other Tools
  • About
  • Contact

Last modified: Jan 10, 2023 By Alexander Williams

How to solve TypeError: __init__() missing 1 required positional argument: 'on_delete' Django

TypeError: __init__() missing 1 required positional argument: 'on_delete' happens when your foreign key field doesn't have on_delete argument.

As you know, from Django 2.0 on_delete is required.

Solve The Issue

To solve this issue, you need to add the on_delete parameter.

For example:


parent = models.ForeignKey(Parent, on_delete=models.CASCADE)

Check the document for more details.

https://docs.djangoproject.com/en/3.2/ref/models/fields/#django.db.models.ForeignKey

Recent Tutorials:

  • Creating an Image Cartoonizer with Flask - Complete with Source Code
  • How to use render_template in Flask
  • Convert Image to Text with Flask (Source Code)
  • Understand How to Work with Table in beautifulsoup
  • Estimating Reading Time of Text and Text File using Python
  • Beautifulsoup Get all Links
  • How to Use BeautifulSoup To Extract Title Tag
  • Convert Your Django Project to a Static Site and Host it for Free

Related Tutorials:

  • Convert Your Django Project to a Static Site and Host it for Free
  • How to build a currency converter in Django
  • How to use Django JsonResponse with example
  • Understand how to use Django CreateView with example
  • How to add a custom pagination in Django Admin interface
  • How to Solve django.contrib.admin.sites.AlreadyRegistered
  • How to Exclude one or multiple objects from Django Queryset
  • How to Access a Queryset in Django DetailView
  • Facebook
  • Twitter
  • Youtube

Copyright PyTutorial Blog Co.