Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Change on_delete rules for Product default_variant field

IKarbowiak310f6f41931b
diff --git a/saleor/product/migrations/0127_auto_20201001_0933.py b/saleor/product/migrations/0127_auto_20201001_0933.py
new file mode 100644
index 0000000000..6cd2166ecf
--- /dev/null
+++ b/saleor/product/migrations/0127_auto_20201001_0933.py
@@ -0,0 +1,25 @@
+# Generated by Django 3.1 on 2020-10-01 09:33
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("product", "0126_product_default_variant"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="product",
+ name="default_variant",
+ field=models.OneToOneField(
+ blank=True,
+ null=True,
+ on_delete=django.db.models.deletion.SET_NULL,
+ related_name="+",
+ to="product.productvariant",
+ ),
+ ),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 4f0e3d2965..80def0d709 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -272,7 +272,7 @@ class Product(SeoModel, ModelWithMetadata, PublishableModel):
"ProductVariant",
blank=True,
null=True,
- on_delete=models.CASCADE,
+ on_delete=models.SET_NULL,
related_name="+",
)
objects = ProductsQueryset.as_manager()