How to Solve Error Message TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when executing python makemigrations

Posted on

This article will focus on the discussion of how to solve the error message as in the title of this article. Actually, the error message is quite clear. It is pointing out a missing argument. An action of executing the command ‘python manage makemigrations’ trigger the error message. It is when there is a need to migrate or to implement model definition in the ‘’ file. The command will transform the model definition into the associated table in the database. The error message itself exist in a complete output as follow :

user@hostname:~/python/django/todoproject$ source /home/user/python/django/env/bin/activate
(env) user@hostname:~/python/django/todoproject$ python makemigrations
Traceback (most recent call last):
  File "", line 21, in 
  File "", line 17, in main
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/", line 381, in execute_from_command_line
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/", line 357, in execute
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/", line 24, in setup
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/apps/", line 114, in populate
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/apps/", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/user/python/django/env/lib/python3.7/importlib/", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1006, in _gcd_import
  File "", line 983, in _find_and_load
  File "", line 967, in _find_and_load_unlocked
  File "", line 677, in _load_unlocked
  File "", line 728, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "/home/user/python/django/todoproject/todoapp/", line 17, in 
    class TodoList(models.Model): #Todolist able name that inherits models.Model
  File "/home/user/python/django/todoproject/todoapp/", line 22, in TodoList
    category = models.ForeignKey(Category, default="general") # a foreignkey
TypeError: __init__() missing 1 required positional argument: 'on_delete'
(env) user@hostname:~/python/django/todoproject$ 

The error itself happens because of the model definition exist in the ‘’ file. There is a content according to the output message above hinting the error part. That part is ‘ category = models.ForeignKey(Category, default=”general”) ‘. Furthermore, that part of the source code specific in that lines is missing 1 required position argument : ‘on_delete’. Actually, according to the above error output message, the solution is simple. Just add that 1 required positional argument. That is the ‘on_delete’ argument according to the same error output message. So, just add the additional argument to the part of the line definiton as follows :

    category = models.ForeignKey(Category, default="general",on_delete=models.CASCADE) # a foreignkey

Soon after, just re-execute the ‘python makemigrations’. If everything runs well, the following is the actual output of the command re-execution as follows :

(env) user@hostname:~/python/django/todoproject$ python makemigrations
Migrations for 'todoapp':
    - Create model Category
    - Create model TodoList
(env) user@hostname:~/python/django/todoproject$ 

Fortunately, it works. Just check the database to find out if the table of ‘Category’ and ‘TodoList’ exist to represent each of the model. The source code is part of the lesson or article exist in the article with the title of ‘How to Build Todoapp with Django’ in this link.

Leave a Reply