From 351b4eda000c0100ee2c0464f704cb464b279098 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Tue, 20 May 2025 08:14:00 +0300 Subject: [PATCH] Features: 1) Add migration to remove existing billing and shipping address columns and re-add them pointing to core.Address; Fixes: 1) Correct on_delete parameter reference from django.db.models.deletion to models.deletion; Extra: 1) Cleanup migration file header and remove unnecessary import; 2) Add comments for better clarity on SQL operations. --- ..._billing_address_order_shipping_address.py | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/core/migrations/0020_order_billing_address_order_shipping_address.py b/core/migrations/0020_order_billing_address_order_shipping_address.py index f7930089..430b124e 100644 --- a/core/migrations/0020_order_billing_address_order_shipping_address.py +++ b/core/migrations/0020_order_billing_address_order_shipping_address.py @@ -1,6 +1,5 @@ -# Generated by Django 5.2 on 2025-05-20 04:59 +# core/migrations/0020_order_billing_address_order_shipping_address.py -import django.db.models.deletion from django.db import migrations, models @@ -10,18 +9,37 @@ class Migration(migrations.Migration): ] operations = [ + migrations.RunSQL( + sql=( + "ALTER TABLE core_order " + "DROP COLUMN IF EXISTS billing_address_id, " + "DROP COLUMN IF EXISTS shipping_address_id;" + ), + reverse_sql=migrations.RunSQL.noop, + ), + migrations.AddField( model_name='order', name='billing_address', - field=models.ForeignKey(blank=True, help_text='the billing address used for this order', null=True, - on_delete=django.db.models.deletion.CASCADE, related_name='billing_address_order', - to='core.address', verbose_name='billing address'), + field=models.ForeignKey( + blank=True, null=True, + on_delete=models.deletion.CASCADE, + related_name='billing_address_order', + to='core.address', + verbose_name='billing address', + help_text='the billing address used for this order', + ), ), migrations.AddField( model_name='order', name='shipping_address', - field=models.ForeignKey(blank=True, help_text='the shipping address used for this order', null=True, - on_delete=django.db.models.deletion.CASCADE, related_name='shipping_address_order', - to='core.address', verbose_name='shipping address'), + field=models.ForeignKey( + blank=True, null=True, + on_delete=models.deletion.CASCADE, + related_name='shipping_address_order', + to='core.address', + verbose_name='shipping address', + help_text='the shipping address used for this order', + ), ), ]