Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 2.0: Add on_delete to ForeignKeys #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aoxborrow
Copy link

@aoxborrow aoxborrow commented Jul 29, 2018

closes #25

@KayEss
Copy link
Member

KayEss commented Jul 29, 2018

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
Copy link
Author

aoxborrow commented Jul 29, 2018

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
Copy link
Author

aoxborrow commented Jul 31, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Django 2.0 compatibility (add "on_delete" to ForeignKeys)
3 participants