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.

Santhosh
  • 83
  • 1
  • 8

2 Answers2

1

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

Sayse
  • 42,633
  • 14
  • 77
  • 146
  • Correct me if I'm wrong. So I need to update all the migration files in all the apps with the new on_delete changes in corresponding models. What happens if I delete all the migration files and recreate it with migrate command? What does the 'apps' in this line refer to -> Path('apps').glob('**/migrations/*.py') ?? – Santhosh Jan 31 '20 at 11:21
  • @Santhosh - Sometimes deleting migration files is not an option and its just as easy to tweak the files yourself, I can't really comment on what that other answer uses, regex replacing in your text editor has worked well enough for me in the past. – Sayse Jan 31 '20 at 11:48
0

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.

Pjl
  • 1,752
  • 18
  • 21