Reputation: 71
I've started to learn Django using the No starch Python Crash Course. While going through the steps to code the 'entries', I cannot migrate the database. The error is shown. I'm using python 3.7 and Django 2.0.7
I've tried using python 3.6 but its still not working
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "E:\Users\HCL\AppData\Local\Programs\Python\Python37\lib\site-
packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "E:\Users\HCL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 347, in execute
django.setup()
File "E:\Users\HCL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "E:\Users\HCL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "E:\Users\HCL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "E:\Users\HCL\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "E:\Users\HCL\Desktop\learning_log\learning_logs\models.py", line 10, in <module>
class Entry(models.Model):
File "E:\Users\HCL\Desktop\learning_log\learning_logs\models.py", line 11, in Entry
topic = models.ForeignKey(Topic)
TypeError: __init__() missing 1 required positional argument: 'on_delete'
Upvotes: 1
Views: 109
Reputation: 27503
change this line in your model Entry
topic = models.ForeignKey(Topic)
to
topic = models.ForeignKey(Topic,on_delete=models.CASCADE)
Upvotes: 4