hotkit / django-async

A simple asynchronous execution Django application with proper database transaction management
http://www.kirit.com/Django%20Async
Boost Software License 1.0
35 stars 20 forks source link

Django 2.0: Add on_delete to ForeignKeys #26

Open aoxborrow opened 6 years ago

aoxborrow commented 6 years ago

closes #25

KayEss commented 6 years ago

Thanks for this. Looks like the Django 1.0 stuff needs to get dropped out.

This changes the first migrations file. Do these not need to be in a new migration so that existing systems will upgrade properly, or is this just making explicit the previous defaults?

aoxborrow commented 6 years ago

good question. I'm not really sure, I just grabbed this commit from @dcollinsn. CASCADE was the default in Django < 2.0, but I don't think on_delete actually changes anything at the database level, so this should be fine?

aoxborrow commented 6 years ago

I just migrated an older Django project, and it looks like you do need to update the original migration files, they simply won't run in Django 2.0. See ticket here: https://code.djangoproject.com/ticket/28677

And in Django 1.9 release notes:

Update models and existing migrations to explicitly set the argument.

https://docs.djangoproject.com/en/dev/releases/1.9/#foreignkey-and-onetoonefield-on-delete-argument

Since on_delete doesn't affect anything at the database level, it's fine to just edit them like this. If you want to be 100% proper you could create a new migration with Django 2.0, then squash them together, effectively creating the same migration seen here.