19👍
Yes, that’s the intended upgrade path as described in the 1.9 release notes:
In order to increase awareness about cascading model deletion, the on_delete argument of ForeignKey and OneToOneField will be required in Django 2.0.
Update models and existing migrations to explicitly set the argument. Since the default is models.CASCADE, add on_delete=models.CASCADE to all ForeignKey and OneToOneFields that don’t use a different option. You can also pass it as the second positional argument if you don’t care about compatibility with older versions of Django.
9👍
To update your code to Django 2
(.*)models.ForeignKey\((((?!on_delete).)*)\)\)
$1models.ForeignKey($2, on_delete=models.CASCADE))
field=models.ForeignKey\((((?!on_delete).)*)\)
field=models.ForeignKey($1, on_delete=models.CASCADE)
(.*)models.OneToOneField\((((?!on_delete).)*)\)\)
$1models.OneToOneField($2, on_delete=models.CASCADE))
You can use these 3 regexes to update your codebase with search and replace feature. Of course, step over by checking each replacement, but having a regex will save you time.
- How can I schedule a Task to execute at a specific time using celery?
- ProgrammingError: relation "django_session" does not exist