mirror of
https://github.com/daniviga/django-ram.git
synced 2025-12-26 07:18:32 +01:00
Better migration fix for Django 6.0
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
# Generated by Django 5.1.2 on 2024-11-27 16:35
|
# Generated by Django 5.1.2 on 2024-11-27 16:35
|
||||||
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models, connection
|
||||||
|
from django.db.utils import ProgrammingError, OperationalError
|
||||||
|
|
||||||
|
|
||||||
def basebook_to_book(apps, schema_editor):
|
def basebook_to_book(apps, schema_editor):
|
||||||
@@ -16,6 +17,19 @@ def basebook_to_book(apps, schema_editor):
|
|||||||
b.authors.set(row.old_authors.all())
|
b.authors.set(row.old_authors.all())
|
||||||
|
|
||||||
|
|
||||||
|
def drop_temporary_tables(apps, schema_editor):
|
||||||
|
try:
|
||||||
|
with connection.cursor() as cursor:
|
||||||
|
cursor.execute(
|
||||||
|
'DROP TABLE IF EXISTS bookshelf_basebook_old_authors'
|
||||||
|
)
|
||||||
|
cursor.execute(
|
||||||
|
'DROP TABLE IF EXISTS bookshelf_basebook_authors'
|
||||||
|
)
|
||||||
|
except (ProgrammingError, OperationalError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@@ -101,10 +115,6 @@ class Migration(migrations.Migration):
|
|||||||
model_name="basebook",
|
model_name="basebook",
|
||||||
name="old_title",
|
name="old_title",
|
||||||
),
|
),
|
||||||
# migrations.RemoveField(
|
|
||||||
# model_name="basebook",
|
|
||||||
# name="old_authors",
|
|
||||||
# ),
|
|
||||||
migrations.RemoveField(
|
migrations.RemoveField(
|
||||||
model_name="basebook",
|
model_name="basebook",
|
||||||
name="old_publisher",
|
name="old_publisher",
|
||||||
@@ -138,4 +148,16 @@ class Migration(migrations.Migration):
|
|||||||
},
|
},
|
||||||
bases=("bookshelf.basebook",),
|
bases=("bookshelf.basebook",),
|
||||||
),
|
),
|
||||||
|
# Required by Dajngo 6.0 on SQLite
|
||||||
|
migrations.SeparateDatabaseAndState(
|
||||||
|
state_operations=[
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="basebook",
|
||||||
|
name="old_authors",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
database_operations=[
|
||||||
|
migrations.RunPython(drop_temporary_tables)
|
||||||
|
]
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user