Skip to content

Commit b8095c9

Browse files
dilin-spmilind-shakya-sp
authored andcommitted
Set PeriodicTask.name max_length = 191 to avoid issues with MySQL indexes.
Add readme Add test settings Remove index related changes
1 parent 786290c commit b8095c9

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ pip command::
269269

270270
$ pip install https://github.com/celery/django-celery-beat/zipball/master#egg=django-celery-beat
271271

272+
Issues with mysql
273+
-----------------
274+
If you want to run ``django-celery-beat`` with MySQL, you might run into some issues.
275+
276+
One such issue is when you try to run ``python manage.py migrate django_celery_beat``, you might get the following error::
277+
django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')
278+
To get around this issue, you can set::
279+
DJANGO_CELERY_BEAT_NAME_MAX_LENGTH=191
280+
(or any other value if any other db other than MySQL is causing similar issues.)
281+
max_length of **191** seems to work for MySQL.
282+
272283

273284
TZ Awareness:
274285
-------------

django_celery_beat/migrations/0001_initial.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from django.db import migrations, models
66
import django.db.models.deletion
7+
from django.conf import settings
78

89

910
class Migration(migrations.Migration):
@@ -71,8 +72,15 @@ class Migration(migrations.Migration):
7172
auto_created=True, primary_key=True,
7273
serialize=False, verbose_name='ID')),
7374
('name', models.CharField(
74-
help_text='Useful description', max_length=200,
75-
unique=True, verbose_name='name')),
75+
help_text='Useful description',
76+
max_length=getattr(
77+
settings,
78+
'DJANGO_CELERY_BEAT_NAME_MAX_LENGTH',
79+
200
80+
),
81+
unique=True,
82+
verbose_name='name'
83+
)),
7684
('task', models.CharField(
7785
max_length=200, verbose_name='task name')),
7886
('args', models.TextField(

django_celery_beat/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,12 @@ class PeriodicTask(models.Model):
317317
"""Model representing a periodic task."""
318318

319319
name = models.CharField(
320-
max_length=200, unique=True,
320+
max_length=getattr(
321+
settings,
322+
'DJANGO_CELERY_BEAT_NAME_MAX_LENGTH',
323+
200
324+
),
325+
unique=True,
321326
verbose_name=_('Name'),
322327
help_text=_('Short Description For This Task'),
323328
)

t/proj/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@
123123
# https://docs.djangoproject.com/en/1.9/howto/static-files/
124124

125125
STATIC_URL = '/static/'
126+
DJANGO_CELERY_BEAT_NAME_MAX_LENGTH = 191
126127
DJANGO_CELERY_BEAT_TZ_AWARE = True

0 commit comments

Comments
 (0)