Django alterfield migration to textfield fails [duplicate]
The migration for Django package django-mail-queue
contains the following in relevant part:
migrations.AlterField(
model_name='mailermessage',
name='to_address',
field=models.TextField(db_index=True, verbose_name='To'),
),
But it fails on MySQL 9.0.1 (Django 5.1.5) with the following error:
django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'to_address'
used in key specification without a key length")
Any idea why? I found a closed bug-report for Django (from some years ago) in which this kind of AlterField request had problems, but it appears to be unrelated.
The field was created in migration 0001 with the following:
migrations.CreateModel(
name='MailerMessage',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False,
auto_created=True, primary_key=True)),
('subject', models.CharField(max_length=250, verbose_name='Subject', blank=True)),
('to_address', models.TextField(verbose_name='To')),
('bcc_address', models.TextField(verbose_name='BCC', blank=True)),
('from_address', models.EmailField(max_length=250, verbose_name='From')),
('content', models.TextField(verbose_name='Content', blank=True)),
('html_content', models.TextField(verbose_name='HTML Content', blank=True)),
('app', models.CharField(max_length=250, verbose_name='App', blank=True)),
('sent', models.BooleanField(default=False, verbose_name='Sent', editable=False)),
('last_attempt', models.DateTimeField(verbose_name='Last attempt',
null=True, editable=False, blank=True)),
],
options={
'verbose_name': 'Message',
'verbose_name_plural': 'Messages',
},
bases=(models.Model,),
),
There are no other references to this field in the list of migrations.
The sqlmigrate
command suggested below produced the following output:
--
-- Alter field file_attachment on attachment
--
-- (no-op)
--
-- Alter field sent on mailermessage
--
CREATE INDEX `mailqueue_mailermessage_sent_5a2c49dd` ON `mailqueue_mailermessage` (`sent`);
--
-- Alter field to_address on mailermessage
--
CREATE INDEX `mailqueue_mailermessage_to_address_88fb3d2d` ON `mailqueue_mailermessage` (`to_address`);
But I don't know if the problem is resolved or if it will happen again in production.