Skip to content

Commit

Permalink
Set PeriodicTask.name max_length = 191 to avoid issues with MySQL ind…
Browse files Browse the repository at this point in the history
…exes.

Add readme

Add test settings

Remove index related changes
  • Loading branch information
dilin-sp authored and milind-shakya-sp committed Dec 4, 2018
1 parent 52b4e01 commit 510da36
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ pip command::

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

Issues with mysql
-----------------
If you want to run ``django-celery-beat`` with MySQL, you might run into some issues.

One such issue is when you try to run ``python manage.py migrate django_celery_beat``, you might get the following error::
django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')
To get around this issue, you can set::
DJANGO_CELERY_BEAT_NAME_MAX_LENGTH=191
(or any other value if any other db other than MySQL is causing similar issues.)
max_length of **191** seems to work for MySQL.


TZ Awareness:
-------------
Expand Down
12 changes: 10 additions & 2 deletions django_celery_beat/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings


class Migration(migrations.Migration):
Expand Down Expand Up @@ -71,8 +72,15 @@ class Migration(migrations.Migration):
auto_created=True, primary_key=True,
serialize=False, verbose_name='ID')),
('name', models.CharField(
help_text='Useful description', max_length=200,
unique=True, verbose_name='name')),
help_text='Useful description',
max_length=getattr(
settings,
'DJANGO_CELERY_BEAT_NAME_MAX_LENGTH',
200
),
unique=True,
verbose_name='name'
)),
('task', models.CharField(
max_length=200, verbose_name='task name')),
('args', models.TextField(
Expand Down
10 changes: 8 additions & 2 deletions django_celery_beat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,14 @@ class PeriodicTask(models.Model):
"""Model representing a periodic task."""

name = models.CharField(
_('name'), max_length=200, unique=True,
help_text=_('Useful description'),
_('name'),
max_length=getattr(
settings,
'DJANGO_CELERY_BEAT_NAME_MAX_LENGTH',
200
),
unique=True,
help_text=_('Useful description')
)
task = models.CharField(_('task name'), max_length=200)
interval = models.ForeignKey(
Expand Down
1 change: 1 addition & 0 deletions t/proj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
DJANGO_CELERY_BEAT_NAME_MAX_LENGTH = 191
DJANGO_CELERY_BEAT_TZ_AWARE = True

0 comments on commit 510da36

Please sign in to comment.