mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Ensures all existing one to one fields are nulled before altering the field
This commit is contained in:
		@@ -4,6 +4,17 @@ from django.db import migrations, models
 | 
				
			|||||||
import django.db.models.deletion
 | 
					import django.db.models.deletion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _attempted_task(apps, schema_editor):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Remove any existing attempted_task one to one fields.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    task_model = apps.get_model("documents", "PaperlessTask")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for task in task_model.objects.all():
 | 
				
			||||||
 | 
					        task.attempted_task = None
 | 
				
			||||||
 | 
					        task.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Migration(migrations.Migration):
 | 
					class Migration(migrations.Migration):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dependencies = [
 | 
					    dependencies = [
 | 
				
			||||||
@@ -12,6 +23,10 @@ class Migration(migrations.Migration):
 | 
				
			|||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    operations = [
 | 
					    operations = [
 | 
				
			||||||
 | 
					        migrations.RunPython(
 | 
				
			||||||
 | 
					            code=_attempted_task,
 | 
				
			||||||
 | 
					            reverse_code=migrations.RunPython.noop,
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
        migrations.RemoveField(
 | 
					        migrations.RemoveField(
 | 
				
			||||||
            model_name="paperlesstask",
 | 
					            model_name="paperlesstask",
 | 
				
			||||||
            name="created",
 | 
					            name="created",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user