-
Notifications
You must be signed in to change notification settings - Fork 192
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
Fix on_delete deprecation warnings #653
Conversation
@sks444 A whole bunch of tests are failing. Please investigate the reason and post your findings. |
Hi @ananyo2012, tests are fixed now, a merge migration file was missing. |
@sks444 Are these migration files updated manually ? As per my understanding makemigrations creates new migrations instead of modifying older ones |
@ananyo2012, yes, I am also modifying the old migration files manually for the first time ^_^. But here is an explanation on why we needed these changes: Django requires a default But the reason I had to update the old migration file is that those migrations files still have |
Ah I see. We need to test this properly on the existing application and
check that it doesn't break anything in production. Will check this
tomorrow and update.
…On Sun, 22 Mar, 2020, 10:40 PM Shrikrishna Singh, ***@***.***> wrote:
As per my understanding makemigrations creates new migrations instead of
modifying older ones
@ananyo2012 <https://github.com/ananyo2012>, yes, I am also modifying the
old migration files manually for the first time ^_^. But here is an
explanation on why we needed these changes:
Django requires a default on_delete param when we use ForeignKey and
OneToOne, so now as I have added on_delete to our models it is there for
the new migrations files.
But the reason I had to update the old migration file is that those
migrations files still have ForeignKey fields defined which doesn't have
on_delete param which raises a deprecation warnings. Now as there is no
other way to get rid of those warnings, so we will have to add the default
value of on_delete to those migration files manually. Actually, Django
also recommended to do this when they added this change.
Source
<https://stackoverflow.com/questions/51933474/is-it-correct-to-modify-old-migration-files-in-django>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#653 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACQAER2KXYCE6MGOLLASQGDRIZBAPANCNFSM4LRJ6MYQ>
.
|
@sks444 Can you provision a database locally, apply the old migrations, then apply the migrations again which are modified? This would give an idea of whether they break anything. |
@palnabarun Modification in the old migration files will not affect anything, as I have added a default value to To verify this behaviour I ran
|
Only migration we need to apply to the database is for the new migration files which is created only when I set |
This seems fine to me. My only not-very-functional concern is that we have a merge migration, due to seemingly out-of-order updates to our migrations. I personally prefer to keep the migration history linear, so if that could be fixed, that'd be great! Other than that, the code is basically not very readable or reviewable, which is just making a stronger case for #655 to me. :) |
eae9014
to
238d2fa
Compare
@pradyunsg I fixed the merge migrations problem. Generally I also don't prefer merge migrations, but I noticed it in the codebase at few places..anyway.
Are you referring to the migration files changes? I think we can spare those as they are auto generated? To make this pr reviewable I think I can create a separate pr for manual migration files changes? |
I was, yes. It's fine for this PR. I was mostly just thinking aloud, so that I can come back it later. :) |
Yeah, I am also feeling that while going through the codebase, it doesn't look a very newcomer friendly. Hard to read as well as there are so many things going on in a single method which I think can be split into multiple or maybe a class can be used and a bit doc string can also be helpful. But anyway, let's work on these and see how far we can go. :) |
238d2fa
to
2c3d5aa
Compare
@sks444 Since you made the |
Yes @ananyo2012 they are auto generated when I ran makemigrations with changes to old migration and still needed, as I am changing the default value of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to go. I applied the migrations over the existing DB, and everything seems to be unchanged. Also tested the CASCADE functionality on conference and it works fine. Deletes the cascaded records of the conference.
Nice work @sks444 👍 Ship it !
Thanks @ananyo2012 :) After this, I think I will move ahead with resolving warnings from the dependencies and move towards #611 Maybe while upgrading the dependencies we will have to upgrade Django to 1.11 as I think most of them won't be supporting Django 1.9. |
Gentle ping @sks444, could you merge master into this branch (discarding incoming changes) and run That should resolve nearly all the merge conflicts, and then a commit for fixing anything else that shows up, would be great! |
@pradyunsg will
|
2c3d5aa
to
18b5f93
Compare
@pradyunsg Can you have a look, I couldn't run |
@sk444 would you be OK with me pushing commits to this PR? |
Sure. :) |
Hey @sk444, could you file an issue describing why you couldn't run |
Hi @pradyunsg, I have documented the problems I am facing while running |
18b5f93
to
87df62f
Compare
@sks444 Would it be OK if I take this PR forward from here? I feel like it'd be easier to take this to completion myself, while we figure out a good way to fix the development setup issues for you. Plus, this is basically ready other than linting issues, which I really don't want to bother you with. :) |
Sure @pradyunsg that would be great, thank you for your help. :) Although I have tried to fix most of the linting issues there is, but
Which I think is because I don't have |
Related to #643, #652
Django 2 requires to have a
on_delete
parameter when usingForeignKey
relations.on_delete
parameter defines what should happen to the related model when the respective field model gets deleted. E.g:In the above model what should happen to
ConferenceSetting
object whenConference
is deleted. In this caseon_delete=models.CASCADE
means thatConferenceSetting
will also gets deleted.But when we use
on_delete=models.SET_NULL
it sets the respective field tonull
instead of deleting the whole model object. E.g:So in my changes: as I am new to the codebase and don't have much familiarity with each model behaviour.
I have used
on_delete=models.SET_NULL
if the related field is nullable otherwiseon_delete=models.CASCADE
Also added
on_delete=django.db.models.deletion.CASCADE
to old migration files as it is the default value provided by Django.