mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Fix BuildItem with empty BuildLine reference (#7178)
This commit is contained in:
parent
e24c4c56fa
commit
fc9c75e4ca
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.12 on 2024-05-08 01:38
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('build', '0048_build_project_code'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='builditem',
|
||||||
|
name='build_line',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='allocations', to='build.buildline'),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,26 @@
|
|||||||
|
# Generated by Django 4.2.12 on 2024-05-08 01:38
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def forward(apps, schema_editor):
|
||||||
|
"""Find and delete any BuildItem instances which have a null BuildLine field."""
|
||||||
|
|
||||||
|
BuildItem = apps.get_model('build', 'BuildItem')
|
||||||
|
|
||||||
|
items = BuildItem.objects.filter(build_line=None)
|
||||||
|
|
||||||
|
if items.count() > 0:
|
||||||
|
print(f"Deleting {items.count()} BuildItem objects with null BuildLine field")
|
||||||
|
items.delete()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('build', '0049_alter_builditem_build_line'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(forward, reverse_code=migrations.RunPython.noop),
|
||||||
|
]
|
@ -1569,7 +1569,7 @@ class BuildItem(InvenTree.models.InvenTreeMetadataModel):
|
|||||||
|
|
||||||
build_line = models.ForeignKey(
|
build_line = models.ForeignKey(
|
||||||
BuildLine,
|
BuildLine,
|
||||||
on_delete=models.SET_NULL, null=True,
|
on_delete=models.CASCADE, null=True,
|
||||||
related_name='allocations',
|
related_name='allocations',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user