简体   繁体   中英

Upgrading django from 1.8 to 2.2.0

Im upgrading my django project from 1.8 to 2.2.0(Using Python 3.6 from virtualenv). I have done the below changes.

  1. Added on_delete to all the Foreign Key fields
  2. Changed the url reverse import as from django.urls import reverse
  3. Included path/re_path instead of url in all the app's url files.
  4. Changed the MIDDLEWARE_CLASSES import in settings files to MIDDLEWARE = {}

I tried to run the server, still it says "TypeError: init () missing 1 required positional argument: 'on_delete' and it is pointing to /usr2/santhosh/myproject/myapp/migrations/0002_abc.py

What should I do now? Do I need to delete all the migration files from the app and re-run python manage.py migrate or what?? Help me you are aware.

Migration files are still just python files so you need to update all references inside those too.

If you want an easy way to do this, take a look at Easy way to set on_delete across entire application

That message means that you forgot to change a FK. Use this to know what models are.

`cat [your_model].py | egrep -i --color -o 'models\.ForeignKey\((.*?)'   | egrep -i -v 'on_delete'`, 

don't forget to doing this in every type of relationship, not just ForeignKey types, also OneToOne ...etc.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM