mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fixes up some issues with the migrations and type mismatches
This commit is contained in:
		| @@ -41,7 +41,7 @@ class Migration(migrations.Migration): | ||||
|                         null=True, | ||||
|                         on_delete=django.db.models.deletion.CASCADE, | ||||
|                         related_name="attempted_task", | ||||
|                         # This is a dummy field, AlterField in 1026 will set to correct value | ||||
|                         # This is a dummy field, 1026 will fix up the column | ||||
|                         # This manual change is required, as django doesn't django doesn't really support | ||||
|                         # removing an app which has migration deps like this | ||||
|                         to="documents.document", | ||||
|   | ||||
| @@ -11,8 +11,9 @@ def _attempted_task(apps, schema_editor): | ||||
|     task_model = apps.get_model("documents", "PaperlessTask") | ||||
| 
 | ||||
|     for task in task_model.objects.all(): | ||||
|         task.attempted_task = None | ||||
|         task.save() | ||||
|         if hasattr(task, "attempted_task"): | ||||
|             task.attempted_task = None | ||||
|             task.save() | ||||
| 
 | ||||
| 
 | ||||
| class Migration(migrations.Migration): | ||||
| @@ -23,10 +24,6 @@ class Migration(migrations.Migration): | ||||
|     ] | ||||
| 
 | ||||
|     operations = [ | ||||
|         migrations.RunPython( | ||||
|             code=_attempted_task, | ||||
|             reverse_code=migrations.RunPython.noop, | ||||
|         ), | ||||
|         migrations.RemoveField( | ||||
|             model_name="paperlesstask", | ||||
|             name="created", | ||||
| @@ -39,7 +36,21 @@ class Migration(migrations.Migration): | ||||
|             model_name="paperlesstask", | ||||
|             name="started", | ||||
|         ), | ||||
|         migrations.AlterField( | ||||
|         # Ensure any existing PaperlessTask.attempted_task are nulled | ||||
|         # This ensures nothing is pointing to a django-q model | ||||
|         migrations.RunPython( | ||||
|             code=_attempted_task, | ||||
|             reverse_code=migrations.RunPython.noop, | ||||
|         ), | ||||
|         # Remove the field from the model | ||||
|         migrations.RemoveField( | ||||
|             model_name="paperlesstask", | ||||
|             name="attempted_task", | ||||
|         ), | ||||
|         # Add the field back, pointing to the correct model | ||||
|         # This resolves a problem where the temporary change in 1022 | ||||
|         # results in a type mismatch | ||||
|         migrations.AddField( | ||||
|             model_name="paperlesstask", | ||||
|             name="attempted_task", | ||||
|             field=models.OneToOneField( | ||||
| @@ -50,4 +61,14 @@ class Migration(migrations.Migration): | ||||
|                 to="django_celery_results.taskresult", | ||||
|             ), | ||||
|         ), | ||||
|         # Drop the django-q tables entirely | ||||
|         migrations.RunSQL( | ||||
|             "DROP TABLE IF EXISTS django_q_ormq", reverse_sql=migrations.RunSQL.noop | ||||
|         ), | ||||
|         migrations.RunSQL( | ||||
|             "DROP TABLE IF EXISTS django_q_schedule", reverse_sql=migrations.RunSQL.noop | ||||
|         ), | ||||
|         migrations.RunSQL( | ||||
|             "DROP TABLE IF EXISTS django_q_task", reverse_sql=migrations.RunSQL.noop | ||||
|         ), | ||||
|     ] | ||||
| @@ -1,24 +0,0 @@ | ||||
| # Generated by Django 4.0.7 on 2022-09-05 21:39 | ||||
|  | ||||
| from django.db import migrations | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [ | ||||
|         ("documents", "1026_remove_paperlesstask_created_and_more"), | ||||
|     ] | ||||
|  | ||||
|     # Manual SQL commands to drop the django_q related tables | ||||
|     # if they exist | ||||
|     operations = [ | ||||
|         migrations.RunSQL( | ||||
|             "DROP TABLE IF EXISTS django_q_ormq", reverse_sql=migrations.RunSQL.noop | ||||
|         ), | ||||
|         migrations.RunSQL( | ||||
|             "DROP TABLE IF EXISTS django_q_schedule", reverse_sql=migrations.RunSQL.noop | ||||
|         ), | ||||
|         migrations.RunSQL( | ||||
|             "DROP TABLE IF EXISTS django_q_task", reverse_sql=migrations.RunSQL.noop | ||||
|         ), | ||||
|     ] | ||||
		Reference in New Issue
	
	Block a user
	 Trenton H
					Trenton H