Skip to content

Commit

Permalink
fix: sql_require_primary_key compatibility (#116)
Browse files Browse the repository at this point in the history
* fix: sql_require_primary_key compatibility

In MySQL, if the `sql_require_primary_key` is turned on, no table can
exist without a primary key. Since the migration 0005 drops the primary
key field before model deletion, the table misses the primary key, hence
the migration will fail.

To prevent migration failure, we swap the primary key before dropping
the `revisionpluginrevision_ptr` field which is the actual primary key.
In case the migration need to be reverted, the opposite will happen and
we set the `revisionpluginrevision_ptr` as the primary key.

When selecting the new primary key, it doesn't really matter what we
set, since at the end of the migration we drop the whole table.

Signed-off-by: Gabor Boros <[email protected]>
  • Loading branch information
gabor-boros authored Jun 17, 2022
1 parent ee35390 commit 0a1d555
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def is_requirement(line):

setup(
name="django-wiki",
version="1.1.0",
version="1.1.1",
author="Benjamin Bach",
author_email="[email protected]",
description="A wiki system written for the Django framework.",
Expand Down
4 changes: 0 additions & 4 deletions wiki/migrations/0005_remove_attachments_and_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class Migration(migrations.Migration):
model_name='attachmentrevision',
name='user',
),
migrations.RemoveField(
model_name='imagerevision',
name='revisionpluginrevision_ptr',
),
migrations.DeleteModel(
name='Attachment',
),
Expand Down

0 comments on commit 0a1d555

Please sign in to comment.