From 1a5ce981a435d62de16e01fd357b3621bcbd8e54 Mon Sep 17 00:00:00 2001 From: Branko Majic Date: Mon, 26 Apr 2021 21:53:51 +0200 Subject: [PATCH] Fix compatability with MySQL/MariaDB (issue #16): - MariaDB can create index for vartext columns only if the total maximum length does not exceed 3072 bytes. When using latin1, this translated into column max length of 3072. However, when using more complex encoding types, this can be substantially less. In case of utf8mb4 encoding the maximum is 4 times less, since a single character may require as much as 4 bytes to encode (768). - Limit the maximum length for the old_path field to 512 characters. This should be more than sufficient for most redirects. - Changes made to an older migration for simplicity sake - this should cover issues on new installations, while new migration should handle existing installations. --- .../migrations/0002_auto_20151217_1938.py | 2 +- .../migrations/0005_auto_20210425_1321.py | 17 +++++++++++++++++ regex_redirects/models.py | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 regex_redirects/migrations/0005_auto_20210425_1321.py diff --git a/regex_redirects/migrations/0002_auto_20151217_1938.py b/regex_redirects/migrations/0002_auto_20151217_1938.py index 73b3b77..f9bff9b 100644 --- a/regex_redirects/migrations/0002_auto_20151217_1938.py +++ b/regex_redirects/migrations/0002_auto_20151217_1938.py @@ -19,6 +19,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='redirect', name='old_path', - field=models.CharField(help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'.", max_length=2000, verbose_name='redirect from', db_index=True), + field=models.CharField(help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'.", max_length=512, verbose_name='redirect from', db_index=True), ), ] diff --git a/regex_redirects/migrations/0005_auto_20210425_1321.py b/regex_redirects/migrations/0005_auto_20210425_1321.py new file mode 100644 index 0000000..dc7043a --- /dev/null +++ b/regex_redirects/migrations/0005_auto_20210425_1321.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('regex_redirects', '0004_auto_20170512_1349'), + ] + + operations = [ + migrations.AlterField( + model_name='redirect', + name='old_path', + field=models.CharField(db_index=True, help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'.", max_length=512, verbose_name='redirect from'), + ), + ] diff --git a/regex_redirects/models.py b/regex_redirects/models.py index 3d8377b..5a836a3 100644 --- a/regex_redirects/models.py +++ b/regex_redirects/models.py @@ -6,7 +6,7 @@ class Redirect(models.Model): old_path = models.CharField(_('redirect from'), - max_length=2000, + max_length=512, db_index=True, help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'.")) new_path = models.CharField(_('redirect to'),