My project was working fine with django 1.11
This is my manage.py file
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myfoodsite.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
until I upgraded my django to django 2.0.0
By using pip install python=2.0.0
, The output was as follows
(myvenv) shubhendu@shubhendu-HP-Pavilion-g6-Notebook-PC:/home/foodballbear$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/foodballbear/block/models.py", line 41, in <module>
class Post(models.Model):
File "/home/foodballbear/block/models.py", line 42, in Post
author = models.ForeignKey('auth.User')
TypeError: __init__() missing 1 required positional argument: 'on_delete'
I am now developing it well on Django 1.11 but how can I make it run on Django 2.0?
As documentation for ForeignKey in Django 1.1 states on_delete is becoming required in Django 2.0
ForeignKey
A many-to-one relationship. Requires two positional arguments: the class to which the model is related and the on_delete option. (on_delete isn't actually required, but not providing it gives a deprecation warning. It will be required in Django 2.0.)
Also your error points to the same
author = models.ForeignKey('auth.User')
TypeError: __init__() missing 1 required positional argument: 'on_delete'
You should set on_delete attribute on each foreign key for it to be Django 2.0 compatible
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.