#28065: Optimize SchemaEditor.alter_field() to avoid dropping foreign key
constraints if not needed
-------------------------------------+-------------------------------------
Reporter: Cameron Dawson | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: 1.11
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):
* status: new => closed
* type: Bug => Cleanup/optimization
* resolution: => duplicate
Comment:
The migration is needed as
[https://docs.djangoproject.com/en/stable/topics/migrations/#the-commands
explained in the documentation]:
Django will make migrations for any change to your models or fields -
even options that don’t affect the database - as the only way it can
reconstruct a field correctly is to have all the changes in the history,
and you might need those options in some data migrations later on (for
example, if you’ve set custom validators).
but possibly the operation could be optimized so that SQL isn't executed
for changes to non-database options. This is a duplicate of #25253.
Incidentally, the output for `AlterField` I see is:
{{{
ALTER TABLE `t28065_jobdetail` DROP FOREIGN KEY
`t28065_jobdetail_job_id_7adae3b8_fk_t28065_job_id`;
ALTER TABLE `t28065_jobdetail` ADD CONSTRAINT
`t28065_jobdetail_job_id_7adae3b8_fk_t28065_job_id` FOREIGN KEY (`job_id`)
REFERENCES `t28065_job` (`id`);
}}}
Nothing about `CREATE INDEX` as you mentioned in the ticket. Not sure if
you might be using a third-party MySQL backend or something.
--
Ticket URL: <https://code.djangoproject.com/ticket/28065#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/062.5b35f233ef9d3118a635ffd2d3f0dfea%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.