#31335: [mysql] Renaming a foreign key field that's also included in an index
fails
with "Cannot drop index 'foo_idx': needed in a foreign key constraint"
----------------------------------+--------------------------------------
Reporter: Stephen Finucane | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Comment (by Stephen Finucane):
Here's the modified migration that works around the issue, for
completeness' sake:
{{{
$ cat core/migrations/0002_auto_20200303_1424.py
# Generated by Django 3.0.3 on 2020-03-03 14:24
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='article',
field=models.ForeignKey(
db_constraint=False,
on_delete=django.db.models.deletion.CASCADE,
related_name='comments',
related_query_name='comment',
to='core.Article',
),
),
migrations.RemoveIndex(
model_name='comment',
name='comment_list_covering_idx',
),
migrations.RenameField(
model_name='comment',
old_name='article',
new_name='foo',
),
migrations.AddIndex(
model_name='comment',
index=models.Index(fields=['foo', 'date'],
name='comment_list_covering_idx'),
),
migrations.AlterField(
model_name='comment',
name='foo',
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='comments',
related_query_name='comment',
to='core.Article',
),
),
]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31335#comment:1>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.759c4515843426f4142d62bbbf45d203%40djangoproject.com.