#31186: Error updating unique field
-------------------------------------+-------------------------------------
Reporter: Kailegh | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.2
Severity: Normal | Resolution:
Keywords: migration, | Triage Stage:
TextField, CharField | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):
* type: Uncategorized => Bug
Old description:
> Hi, I think I have discovered a bug, if you have a field like the
> following:
> audio_name = models.CharField(blank=False, max_length=255)
> and decide to change it to the following one:
>
> audio_name = models.TextField(blank=False)
>
> it generates the following migration code:
>
> operations = [
> migrations.AlterModelOptions(
> name='s3_bucket_audios',
> options={},
> ),
> migrations.AlterField(
> model_name='s3_bucket_audios',
> name='audio_name',
> field=models.TextField(help_text='name of the audio in the s3
> bucket'),
> ),
> migrations.AlterUniqueTogether(
> name='s3_bucket_audios',
> unique_together=set(),
> ),
> ]
>
> However it that field was being use in a unique condition:
> class Meta:
> ordering = [ "audio_name"]
> unique_together = ('audio_name')
>
> you get the following error:
> django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'audio_name'
> used in key specification without a key length")
>
> That is because it changes the field type before changing the unique
> condition, I think the order should be handled automatically, I had to
> change the code manually to:
>
> operations = [
> migrations.AlterModelOptions(
> name='s3_bucket_audios',
> options={},
> ),
> migrations.AlterUniqueTogether(
> name='s3_bucket_audios',
> unique_together=set(),
> ),
> migrations.AlterField(
> model_name='s3_bucket_audios',
> name='audio_name',
> field=models.TextField(help_text='name of the audio in the s3
> bucket'),
> ),
> ]
>
> It is not a big issue anyway...
> Thanks a lot for your amazing work!!
New description:
Hi, I think I have discovered a bug, if you have a field like the
following:
{{{
audio_name = models.CharField(blank=False, max_length=255)
}}}
and decide to change it to the following one:
{{{
audio_name = models.TextField(blank=False)
}}}
it generates the following migration code:
{{{
operations = [
migrations.AlterModelOptions(
name='s3_bucket_audios',
options={},
),
migrations.AlterField(
model_name='s3_bucket_audios',
name='audio_name',
field=models.TextField(help_text='name of the audio in the s3
bucket'),
),
migrations.AlterUniqueTogether(
name='s3_bucket_audios',
unique_together=set(),
),
]
}}}
However it that field was being use in a unique condition:
{{{
class Meta:
ordering = [ "audio_name"]
unique_together = ('audio_name')
}}}
you get the following error:
{{{
django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'audio_name'
used in key specification without a key length")
}}}
That is because it changes the field type before changing the unique
condition, I think the order should be handled automatically, I had to
change the code manually to:
{{{
operations = [
migrations.AlterModelOptions(
name='s3_bucket_audios',
options={},
),
migrations.AlterUniqueTogether(
name='s3_bucket_audios',
unique_together=set(),
),
migrations.AlterField(
model_name='s3_bucket_audios',
name='audio_name',
field=models.TextField(help_text='name of the audio in the s3
bucket'),
),
]
}}}
It is not a big issue anyway...
Thanks a lot for your amazing work!!
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31186#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/065.fd1e05cb86d373f5aa4ec0c26a025f7d%40djangoproject.com.