Repository: CiviWiki/OpenCiviWiki

Issue:
Make `linked_civis` and `response_civis` fields optional on Civi model
The `Civi` model contains two required fields that are causing difficulty when starting a fresh project:

- `linked_civis` https://github.com/CiviWiki/OpenCiviWiki/blob/85cd5bf867be4e1987cff3f083fc456904287f9e/project/threads/models.py#L214
- `response_civis` https://github.com/CiviWiki/OpenCiviWiki/blob/85cd5bf867be4e1987cff3f083fc456904287f9e/project/threads/models.py#L215-L221

Since those fields are required, it is not possible to create the first Civi, due to the "chicken and egg" situation where no Civis exist.

## Task

- [x] remove the `response_civis` field
- [x] make the `linked_civis` field optional
- [x] create database migrations with `python manage.py makemigrations`

## Original report
@AbhijithGanesh opened this issue originally with the following information.

### Description

Without fixtures in Civi, it is not possible to create Civis and it is requires a civi to be referenced when created, which makes it impossible to create.




Discussion:
@AbhijithGanesh, could you share the error messages you encounter and also how you get them?
I was unable to get the model instances via the views therefore I registered the models through Admin and tried creating a civi and it returns me the following:
![image](https://user-images.githubusercontent.com/67182544/136074477-7172f60b-1f21-4911-a976-a133b5dba3eb.png)

This is circularly routed.
@AbhijithGanesh, I have repurposed this bug report to make the `linked_civis` field optional and remove the `response_civis` field.
@gorkemarslan and @brylie I wasn't working on this over the weekend, will do this today
Brylie check this
https://github.com/CiviWiki/OpenCiviWiki/blob/develop/project/threads/models.py
We may also need `null=True` here:

https://github.com/CiviWiki/OpenCiviWiki/blob/364b9b1fe85b7610b25d97454342d9c80f5bdb0f/project/threads/models.py#L219


Do we also have the database migration?
I will check and let ya know

Resolving patch:
diff --git a/project/threads/migrations/0002_auto_20211006_1929.py b/project/threads/migrations/0002_auto_20211012_2014.py
similarity index 80%
rename from project/threads/migrations/0002_auto_20211006_1929.py
rename to project/threads/migrations/0002_auto_20211012_2014.py
--- a/project/threads/migrations/0002_auto_20211006_1929.py
+++ b/project/threads/migrations/0002_auto_20211012_2014.py
@@ -1,49 +1,58 @@
-# Generated by Django 3.2.7 on 2021-10-06 19:29
-
-from django.conf import settings
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
-        ('threads', '0001_initial'),
-    ]
-
-    operations = [
-        migrations.AlterModelOptions(
-            name='activity',
-            options={'verbose_name_plural': 'Activities'},
-        ),
-        migrations.RemoveField(
-            model_name='activity',
-            name='account',
-        ),
-        migrations.AddField(
-            model_name='activity',
-            name='user',
-            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
-        ),
-        migrations.AlterField(
-            model_name='civi',
-            name='author',
-            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='civis', to=settings.AUTH_USER_MODEL),
-        ),
-        migrations.AlterField(
-            model_name='rebuttal',
-            name='author',
-            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
-        ),
-        migrations.AlterField(
-            model_name='response',
-            name='author',
-            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
-        ),
-        migrations.AlterField(
-            model_name='thread',
-            name='author',
-            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
-        ),
-    ]
+# Generated by Django 3.2.7 on 2021-10-12 14:44
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+        ('threads', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='activity',
+            options={'verbose_name_plural': 'Activities'},
+        ),
+        migrations.RemoveField(
+            model_name='activity',
+            name='account',
+        ),
+        migrations.RemoveField(
+            model_name='civi',
+            name='response_civis',
+        ),
+        migrations.AddField(
+            model_name='activity',
+            name='user',
+            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
+        ),
+        migrations.AlterField(
+            model_name='civi',
+            name='author',
+            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='civis', to=settings.AUTH_USER_MODEL),
+        ),
+        migrations.AlterField(
+            model_name='civi',
+            name='linked_civis',
+            field=models.ManyToManyField(blank=True, related_name='_threads_civi_linked_civis_+', to='threads.Civi'),
+        ),
+        migrations.AlterField(
+            model_name='rebuttal',
+            name='author',
+            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
+        ),
+        migrations.AlterField(
+            model_name='response',
+            name='author',
+            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
+        ),
+        migrations.AlterField(
+            model_name='thread',
+            name='author',
+            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
+        ),
+    ]
diff --git a/project/threads/models.py b/project/threads/models.py
--- a/project/threads/models.py
+++ b/project/threads/models.py
@@ -216,7 +216,9 @@ class Civi(models.Model):
 
     tags = TaggableManager()
 
-    linked_civis = models.ManyToManyField("self", related_name="links", blank=True)
+    linked_civis = models.ManyToManyField(
+        "self", related_name="links", blank=True
+    )
 
     title = models.CharField(max_length=255, blank=False, null=False)
     body = models.CharField(max_length=1023, blank=False, null=False)


Test patch: