Changes between Initial Version and Version 1 of Ticket #31186


Ignore:
Timestamp:
Jan 20, 2020, 1:36:47 PM (5 years ago)
Author:
Mariusz Felisiak
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31186

    • Property Type UncategorizedBug
  • Ticket #31186 – Description

    initial v1  
    11Hi, I think I have discovered a bug, if you have a field like the following:
     2{{{
    23audio_name = models.CharField(blank=False, max_length=255)
     4}}}
    35and decide to change it to the following one:
    4 
     6{{{
    57audio_name = models.TextField(blank=False)
    6 
     8}}}
    79it generates the following migration code:
    8  
     10{{{
    911   operations = [
    1012        migrations.AlterModelOptions(
     
    1214            options={},
    1315        ),
    14                 migrations.AlterField(
     16        migrations.AlterField(
    1517            model_name='s3_bucket_audios',
    1618            name='audio_name',
     
    2224        ),
    2325    ]
    24 
     26}}}
    2527However it that field was being use in a unique condition:
    26  class Meta:
     28{{{
     29class Meta:
    2730   ordering = [ "audio_name"]
    2831   unique_together = ('audio_name')
    29 
     32}}}
    3033you get the following error:
     34{{{
    3135django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'audio_name' used in key specification without a key length")
    32 
     36}}}
    3337That 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:
    34 
     38{{{
    3539   operations = [
    3640        migrations.AlterModelOptions(
     
    4246            unique_together=set(),
    4347        ),
    44                 migrations.AlterField(
     48        migrations.AlterField(
    4549            model_name='s3_bucket_audios',
    4650            name='audio_name',
     
    4852        ),
    4953    ]
     54}}}
    5055
    5156It is not a big issue anyway...
Back to Top