From b1e86eec17c785d677adb1be831aa5bdf0c59bbc Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Fri, 21 Jan 2022 15:19:19 +0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20updated=20migrations=20scripts?= =?UTF-8?q?=20to=20support=20mysql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sites/migrations/0003_set_site_domain_and_name.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/contrib/sites/migrations/0003_set_site_domain_and_name.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/contrib/sites/migrations/0003_set_site_domain_and_name.py index 080c734bb..b0eaff52b 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/contrib/sites/migrations/0003_set_site_domain_and_name.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/contrib/sites/migrations/0003_set_site_domain_and_name.py @@ -25,6 +25,7 @@ def _update_or_create_site_with_sequence(site_model, connection, domain, name): # greater than the maximum value. max_id = site_model.objects.order_by('-id').first().id with connection.cursor() as cursor: + {% if cookiecutter.database_engine == 'postgresql' -%} cursor.execute("SELECT last_value from django_site_id_seq") (current_id,) = cursor.fetchone() if current_id <= max_id: @@ -32,6 +33,15 @@ def _update_or_create_site_with_sequence(site_model, connection, domain, name): "alter sequence django_site_id_seq restart with %s", [max_id + 1], ) + {% elif cookiecutter.database_engine == 'mysql' -%} + cursor.execute("SELECT MAX(id) FROM django_site") + (current_id,) = cursor.fetchone() + if current_id <= max_id: + cursor.execute( + "ALTER TABLE django_site AUTO_INCREMENT=%s", + [max_id + 1], + ) + {% endif -%} def update_site_forward(apps, schema_editor):