[Fixed]-Is it correct to modify old migration files in Django?


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.



To update your code to Django 2

$1models.ForeignKey($2, on_delete=models.CASCADE))

field=models.ForeignKey($1, on_delete=models.CASCADE)

$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.


Leave a comment