#34151: Adding explicit primary key with different type doesn't update related
ManyToManyFields.
-------------------------------------+-------------------------------------
Reporter: STANISLAV LEPEKHOV | Owner: Carol
| Naranjo
Type: Bug | Status: assigned
Component: Migrations | Version: 4.1
Severity: Normal | Resolution:
Keywords: migrations pk uuid | Triage Stage: Accepted
relation |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Carol Naranjo):
STANISLAV I know this is old, but I could not replicate the issue by just
altering the PK type. At least in my test with sqlite I see the many-to-
many table updated as expected. Can you specify with which DB did you
encountered the issue?
Here is what I tried.
1. Initial setup with initial models (tables already existing in DB but
with empty rows):
{{{
class Place(models.Model):
pass
class StoreChain(models.Model):
pass
places = models.ManyToManyField(Place, blank=True)
}}}
2. Update models
{{{
class Place(models.Model):
id = models.UUIDField(default=uuid.uuid4, editable=False,
primary_key=True)
class StoreChain(models.Model):
id = models.UUIDField(default=uuid.uuid4, editable=False,
primary_key=True)
places = models.ManyToManyField(Place, blank=True)
}}}
3. `makemigrations` and `migrate` ==> I see all 3 tables updated with the
migration file generated as follows:
{{{
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('store', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='place',
name='id',
field=models.UUIDField(default=uuid.uuid4, editable=False,
primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='storechain',
name='id',
field=models.UUIDField(default=uuid.uuid4, editable=False,
primary_key=True, serialize=False),
),
]
}}}
However, if I try renaming the column as well the migration file will be
generated with RemoveField and AddField which at least with my setup using
sqlite is causing another error when applying the migration, hoewever I
would track that new finding as a separate issue in another ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/34151#comment:20>
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 visit
https://groups.google.com/d/msgid/django-updates/0107019cf129252a-1c0508dc-b4f9-4994-aaa8-568a1ec8ef2b-000000%40eu-central-1.amazonses.com.