We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Beta: CachedValue search values may (and do) exceed maximum PostgreSQL B-Tree index row size
### NetBox version

v3.4-beta1

### Python version

3.10

### Steps to Reproduce

1. Have a NetBox instance with a lot of real-life data
2. Try to migrate data from NetBox 3.3.8 to 3.4-beta1

### Expected Behavior

Migrations succeed

### Observed Behavior

Migration `extras.0083_search` fails.

Log:
```bash
$ NETBOX_DELETE_LEGACY_DATA=1 netbox/manage.py migrate
netbox.denormalized: DEBUG    Registering denormalized field <class 'dcim.models.cables.CableTermination'>._device
netbox.denormalized: DEBUG    Registering denormalized field <class 'dcim.models.cables.CableTermination'>._rack
netbox.denormalized: DEBUG    Registering denormalized field <class 'dcim.models.cables.CableTermination'>._location
Operations to perform:
  Apply all migrations: admin, auth, circuits, contenttypes, dcim, django_rq, extras, ipam, sessions, social_django, taggit, tenancy, users, virtualization, wireless
Running migrations:
  Applying extras.0083_search...Reindexing 63 models.
Clearing cached values... 0 entries deleted.
Indexing models
  circuits.circuit... 153 entries cached.
  circuits.circuittermination... 234 entries cached.
  circuits.circuittype... 20 entries cached.
  circuits.provider... 17 entries cached.
  circuits.providernetwork... 2 entries cached.
  dcim.cable... 13284 entries cached.
  dcim.consoleport... 6478 entries cached.
  dcim.consoleserverport... 1378 entries cached.
  dcim.device... 39290 entries cached.
  dcim.devicebay... 422 entries cached.
  dcim.devicerole... 68 entries cached.
  dcim.devicetype... 1022 entries cached.
  dcim.frontport... 21296 entries cached.
  dcim.interface... 805260 entries cached.
  dcim.inventoryitem... None found.
  dcim.location... 469 entries cached.
  dcim.manufacturer... 144 entries cached.
  dcim.module... 40 entries cached.
  dcim.modulebay... 136 entries cached.
  dcim.moduletype... 24 entries cached.
  dcim.platform... 212 entries cached.
  dcim.powerfeed... 48 entries cached.
  dcim.poweroutlet... 464 entries cached.
  dcim.powerpanel... 3 entries cached.
  dcim.powerport... 33112 entries cached.
  dcim.rack... 7741 entries cached.
  dcim.rackreservation... 223 entries cached.
  dcim.rackrole... 33 entries cached.
  dcim.rearport... 17705 entries cached.
  dcim.region... 39 entries cached.
  dcim.site... 270 entries cached.
  dcim.sitegroup... 18 entries cached.
  dcim.virtualchassis... 347 entries cached.
  dcim.virtualdevicecontext... None found.
  ipam.aggregate... 647 entries cached.
  ipam.asn... 18 entries cached.
  ipam.fhrpgroup... None found.
  ipam.ipaddress... 159974 entries cached.
  ipam.iprange... None found.
  ipam.l2vpn... None found.
  ipam.prefix... 43320 entries cached.
  ipam.rir... 12 entries cached.
  ipam.role... 9 entries cached.
  ipam.routetarget... 129 entries cached.
  ipam.service... None found.
  ipam.servicetemplate... None found.
  ipam.vlan... 30219 entries cached.
  ipam.vlangroup... 298 entries cached.
  ipam.vrf... 7301 entries cached.
  extras.journalentry... 23594 entries cached.
  tenancy.contact... 24 entries cached.
  tenancy.contactgroup... 2 entries cached.
  tenancy.contactrole... 6 entries cached.
  tenancy.tenant... 14755 entries cached.
  tenancy.tenantgroup... 9 entries cached.
  virtualization.cluster... 257 entries cached.
  virtualization.clustergroup... 161 entries cached.
  virtualization.clustertype... 14 entries cached.
  virtualization.virtualmachine... 25878 entries cached.
  virtualization.vminterface... 13559 entries cached.
  wireless.wirelesslan... None found.
  wireless.wirelesslangroup... None found.
  wireless.wirelesslink... None found.
Completed. Total entries: 1270138
Traceback (most recent call last):
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.ProgramLimitExceeded: FEHLER:  Indexzeile benötigt 122744 Bytes, Maximalgröße ist 8191


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/dev/netbox/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/commands/migrate.py", line 349, in handle
    post_migrate_state = executor.migrate(
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/migrations/executor.py", line 249, in apply_migration
    with self.connection.schema_editor(
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/base/schema.py", line 164, in __exit__
    self.execute(sql)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/base/schema.py", line 199, in execute
    cursor.execute(sql, params)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 103, in execute
    return super().execute(sql, params)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.OperationalError: FEHLER:  Indexzeile benötigt 122744 Bytes, Maximalgröße ist 8191
```
which translates to: `ERROR: index row requires 122744 bytes, maximum size is 8191`

This seems to be the issue from the perspective of the migration:
* https://github.com/netbox-community/netbox/blob/v3.4-beta1/netbox/extras/migrations/0083_search.py#L12
* causes run of: https://github.com/netbox-community/netbox/blob/v3.4-beta1/netbox/extras/management/commands/reindex.py
* causes run of: https://github.com/netbox-community/netbox/blob/v3.4-beta1/netbox/netbox/search/backends.py#L138

As I am not a database engineer, I'm somewhat guessing my way through here, so in the case, I've missed an obvious configuration value, please have that in mind.

Django seems to use B-Tree indexes in PostgreSQL by default: https://docs.djangoproject.com/en/4.1/ref/models/indexes/#index-options

B-Tree indexes are described in PostgreSQL-docs with a size limit:
> ["The only limitation is that an index entry cannot exceed approximately one-third of a page (after TOAST compression, if applicable)."](https://www.postgresql.org/docs/current/btree-intro.html)

From my understanding of the matter, the size is exceeded as a [CachedValue.value](https://github.com/netbox-community/netbox/blob/v3.4-beta1/netbox/extras/models/search.py#L39) may be too large for a B-Tree index row.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `netbox/extras/migrations/0083_search.py`
Content:
```
1 import sys
2 import uuid
3 
4 import django.db.models.deletion
5 from django.core import management
6 from django.db import migrations, models
7 
8 
9 def reindex(apps, schema_editor):
10     # Build the search index (except during tests)
11     if 'test' not in sys.argv:
12         management.call_command('reindex')
13 
14 
15 class Migration(migrations.Migration):
16 
17     dependencies = [
18         ('circuits', '0041_standardize_description_comments'),
19         ('contenttypes', '0002_remove_content_type_name'),
20         ('dcim', '0166_virtualdevicecontext'),
21         ('extras', '0082_savedfilter'),
22         ('ipam', '0063_standardize_description_comments'),
23         ('tenancy', '0009_standardize_description_comments'),
24         ('virtualization', '0034_standardize_description_comments'),
25         ('wireless', '0008_wirelesslan_status'),
26     ]
27 
28     operations = [
29         migrations.AddField(
30             model_name='customfield',
31             name='search_weight',
32             field=models.PositiveSmallIntegerField(default=1000),
33         ),
34         migrations.CreateModel(
35             name='CachedValue',
36             fields=[
37                 ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
38                 ('timestamp', models.DateTimeField(auto_now_add=True)),
39                 ('object_id', models.PositiveBigIntegerField()),
40                 ('field', models.CharField(max_length=200)),
41                 ('type', models.CharField(max_length=30)),
42                 ('value', models.TextField(db_index=True)),
43                 ('weight', models.PositiveSmallIntegerField(default=1000)),
44                 ('object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='contenttypes.contenttype')),
45             ],
46             options={
47                 'ordering': ('weight', 'object_type', 'object_id'),
48             },
49         ),
50         migrations.RunPython(
51             code=reindex,
52             reverse_code=migrations.RunPython.noop
53         ),
54     ]
55
```

Path: `netbox/extras/models/search.py`
Content:
```
1 import uuid
2 
3 from django.contrib.contenttypes.models import ContentType
4 from django.db import models
5 
6 from utilities.fields import RestrictedGenericForeignKey
7 
8 __all__ = (
9     'CachedValue',
10 )
11 
12 
13 class CachedValue(models.Model):
14     id = models.UUIDField(
15         primary_key=True,
16         default=uuid.uuid4,
17         editable=False
18     )
19     timestamp = models.DateTimeField(
20         auto_now_add=True,
21         editable=False
22     )
23     object_type = models.ForeignKey(
24         to=ContentType,
25         on_delete=models.CASCADE,
26         related_name='+'
27     )
28     object_id = models.PositiveBigIntegerField()
29     object = RestrictedGenericForeignKey(
30         ct_field='object_type',
31         fk_field='object_id'
32     )
33     field = models.CharField(
34         max_length=200
35     )
36     type = models.CharField(
37         max_length=30
38     )
39     value = models.TextField(
40         db_index=True
41     )
42     weight = models.PositiveSmallIntegerField(
43         default=1000
44     )
45 
46     class Meta:
47         ordering = ('weight', 'object_type', 'object_id')
48 
49     def __str__(self):
50         return f'{self.object_type} {self.object_id}: {self.field}={self.value}'
51
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/netbox/extras/migrations/0083_search.py b/netbox/extras/migrations/0083_search.py
--- a/netbox/extras/migrations/0083_search.py
+++ b/netbox/extras/migrations/0083_search.py
@@ -2,6 +2,7 @@
 import uuid
 
 import django.db.models.deletion
+import django.db.models.lookups
 from django.core import management
 from django.db import migrations, models
 
@@ -39,7 +40,7 @@
                 ('object_id', models.PositiveBigIntegerField()),
                 ('field', models.CharField(max_length=200)),
                 ('type', models.CharField(max_length=30)),
-                ('value', models.TextField(db_index=True)),
+                ('value', models.TextField()),
                 ('weight', models.PositiveSmallIntegerField(default=1000)),
                 ('object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='contenttypes.contenttype')),
             ],
diff --git a/netbox/extras/models/search.py b/netbox/extras/models/search.py
--- a/netbox/extras/models/search.py
+++ b/netbox/extras/models/search.py
@@ -36,9 +36,7 @@
     type = models.CharField(
         max_length=30
     )
-    value = models.TextField(
-        db_index=True
-    )
+    value = models.TextField()
     weight = models.PositiveSmallIntegerField(
         default=1000
     )

{"golden_diff": "diff --git a/netbox/extras/migrations/0083_search.py b/netbox/extras/migrations/0083_search.py\n--- a/netbox/extras/migrations/0083_search.py\n+++ b/netbox/extras/migrations/0083_search.py\n@@ -2,6 +2,7 @@\n import uuid\n \n import django.db.models.deletion\n+import django.db.models.lookups\n from django.core import management\n from django.db import migrations, models\n \n@@ -39,7 +40,7 @@\n                 ('object_id', models.PositiveBigIntegerField()),\n                 ('field', models.CharField(max_length=200)),\n                 ('type', models.CharField(max_length=30)),\n-                ('value', models.TextField(db_index=True)),\n+                ('value', models.TextField()),\n                 ('weight', models.PositiveSmallIntegerField(default=1000)),\n                 ('object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='contenttypes.contenttype')),\n             ],\ndiff --git a/netbox/extras/models/search.py b/netbox/extras/models/search.py\n--- a/netbox/extras/models/search.py\n+++ b/netbox/extras/models/search.py\n@@ -36,9 +36,7 @@\n     type = models.CharField(\n         max_length=30\n     )\n-    value = models.TextField(\n-        db_index=True\n-    )\n+    value = models.TextField()\n     weight = models.PositiveSmallIntegerField(\n         default=1000\n     )\n", "issue": "Beta: CachedValue search values may (and do) exceed maximum PostgreSQL B-Tree index row size\n### NetBox version\n\nv3.4-beta1\n\n### Python version\n\n3.10\n\n### Steps to Reproduce\n\n1. Have a NetBox instance with a lot of real-life data\r\n2. Try to migrate data from NetBox 3.3.8 to 3.4-beta1\n\n### Expected Behavior\n\nMigrations succeed\n\n### Observed Behavior\n\nMigration `extras.0083_search` fails.\r\n\r\nLog:\r\n```bash\r\n$ NETBOX_DELETE_LEGACY_DATA=1 netbox/manage.py migrate\r\nnetbox.denormalized: DEBUG    Registering denormalized field <class 'dcim.models.cables.CableTermination'>._device\r\nnetbox.denormalized: DEBUG    Registering denormalized field <class 'dcim.models.cables.CableTermination'>._rack\r\nnetbox.denormalized: DEBUG    Registering denormalized field <class 'dcim.models.cables.CableTermination'>._location\r\nOperations to perform:\r\n  Apply all migrations: admin, auth, circuits, contenttypes, dcim, django_rq, extras, ipam, sessions, social_django, taggit, tenancy, users, virtualization, wireless\r\nRunning migrations:\r\n  Applying extras.0083_search...Reindexing 63 models.\r\nClearing cached values... 0 entries deleted.\r\nIndexing models\r\n  circuits.circuit... 153 entries cached.\r\n  circuits.circuittermination... 234 entries cached.\r\n  circuits.circuittype... 20 entries cached.\r\n  circuits.provider... 17 entries cached.\r\n  circuits.providernetwork... 2 entries cached.\r\n  dcim.cable... 13284 entries cached.\r\n  dcim.consoleport... 6478 entries cached.\r\n  dcim.consoleserverport... 1378 entries cached.\r\n  dcim.device... 39290 entries cached.\r\n  dcim.devicebay... 422 entries cached.\r\n  dcim.devicerole... 68 entries cached.\r\n  dcim.devicetype... 1022 entries cached.\r\n  dcim.frontport... 21296 entries cached.\r\n  dcim.interface... 805260 entries cached.\r\n  dcim.inventoryitem... None found.\r\n  dcim.location... 469 entries cached.\r\n  dcim.manufacturer... 144 entries cached.\r\n  dcim.module... 40 entries cached.\r\n  dcim.modulebay... 136 entries cached.\r\n  dcim.moduletype... 24 entries cached.\r\n  dcim.platform... 212 entries cached.\r\n  dcim.powerfeed... 48 entries cached.\r\n  dcim.poweroutlet... 464 entries cached.\r\n  dcim.powerpanel... 3 entries cached.\r\n  dcim.powerport... 33112 entries cached.\r\n  dcim.rack... 7741 entries cached.\r\n  dcim.rackreservation... 223 entries cached.\r\n  dcim.rackrole... 33 entries cached.\r\n  dcim.rearport... 17705 entries cached.\r\n  dcim.region... 39 entries cached.\r\n  dcim.site... 270 entries cached.\r\n  dcim.sitegroup... 18 entries cached.\r\n  dcim.virtualchassis... 347 entries cached.\r\n  dcim.virtualdevicecontext... None found.\r\n  ipam.aggregate... 647 entries cached.\r\n  ipam.asn... 18 entries cached.\r\n  ipam.fhrpgroup... None found.\r\n  ipam.ipaddress... 159974 entries cached.\r\n  ipam.iprange... None found.\r\n  ipam.l2vpn... None found.\r\n  ipam.prefix... 43320 entries cached.\r\n  ipam.rir... 12 entries cached.\r\n  ipam.role... 9 entries cached.\r\n  ipam.routetarget... 129 entries cached.\r\n  ipam.service... None found.\r\n  ipam.servicetemplate... None found.\r\n  ipam.vlan... 30219 entries cached.\r\n  ipam.vlangroup... 298 entries cached.\r\n  ipam.vrf... 7301 entries cached.\r\n  extras.journalentry... 23594 entries cached.\r\n  tenancy.contact... 24 entries cached.\r\n  tenancy.contactgroup... 2 entries cached.\r\n  tenancy.contactrole... 6 entries cached.\r\n  tenancy.tenant... 14755 entries cached.\r\n  tenancy.tenantgroup... 9 entries cached.\r\n  virtualization.cluster... 257 entries cached.\r\n  virtualization.clustergroup... 161 entries cached.\r\n  virtualization.clustertype... 14 entries cached.\r\n  virtualization.virtualmachine... 25878 entries cached.\r\n  virtualization.vminterface... 13559 entries cached.\r\n  wireless.wirelesslan... None found.\r\n  wireless.wirelesslangroup... None found.\r\n  wireless.wirelesslink... None found.\r\nCompleted. Total entries: 1270138\r\nTraceback (most recent call last):\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py\", line 89, in _execute\r\n    return self.cursor.execute(sql, params)\r\npsycopg2.errors.ProgramLimitExceeded: FEHLER:  Indexzeile ben\u00f6tigt 122744 Bytes, Maximalgr\u00f6\u00dfe ist 8191\r\n\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"/var/dev/netbox/netbox/manage.py\", line 10, in <module>\r\n    execute_from_command_line(sys.argv)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/__init__.py\", line 446, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/__init__.py\", line 440, in execute\r\n    self.fetch_command(subcommand).run_from_argv(self.argv)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/base.py\", line 402, in run_from_argv\r\n    self.execute(*args, **cmd_options)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/base.py\", line 448, in execute\r\n    output = self.handle(*args, **options)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/base.py\", line 96, in wrapped\r\n    res = handle_func(*args, **kwargs)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/core/management/commands/migrate.py\", line 349, in handle\r\n    post_migrate_state = executor.migrate(\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/migrations/executor.py\", line 135, in migrate\r\n    state = self._migrate_all_forwards(\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/migrations/executor.py\", line 167, in _migrate_all_forwards\r\n    state = self.apply_migration(\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/migrations/executor.py\", line 249, in apply_migration\r\n    with self.connection.schema_editor(\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/base/schema.py\", line 164, in __exit__\r\n    self.execute(sql)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/base/schema.py\", line 199, in execute\r\n    cursor.execute(sql, params)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py\", line 103, in execute\r\n    return super().execute(sql, params)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py\", line 67, in execute\r\n    return self._execute_with_wrappers(\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py\", line 80, in _execute_with_wrappers\r\n    return executor(sql, params, many, context)\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py\", line 84, in _execute\r\n    with self.db.wrap_database_errors:\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/utils.py\", line 91, in __exit__\r\n    raise dj_exc_value.with_traceback(traceback) from exc_value\r\n  File \"/var/dev/netbox/venv/lib64/python3.10/site-packages/django/db/backends/utils.py\", line 89, in _execute\r\n    return self.cursor.execute(sql, params)\r\ndjango.db.utils.OperationalError: FEHLER:  Indexzeile ben\u00f6tigt 122744 Bytes, Maximalgr\u00f6\u00dfe ist 8191\r\n```\r\nwhich translates to: `ERROR: index row requires 122744 bytes, maximum size is 8191`\r\n\r\nThis seems to be the issue from the perspective of the migration:\r\n* https://github.com/netbox-community/netbox/blob/v3.4-beta1/netbox/extras/migrations/0083_search.py#L12\r\n* causes run of: https://github.com/netbox-community/netbox/blob/v3.4-beta1/netbox/extras/management/commands/reindex.py\r\n* causes run of: https://github.com/netbox-community/netbox/blob/v3.4-beta1/netbox/netbox/search/backends.py#L138\r\n\r\nAs I am not a database engineer, I'm somewhat guessing my way through here, so in the case, I've missed an obvious configuration value, please have that in mind.\r\n\r\nDjango seems to use B-Tree indexes in PostgreSQL by default: https://docs.djangoproject.com/en/4.1/ref/models/indexes/#index-options\r\n\r\nB-Tree indexes are described in PostgreSQL-docs with a size limit:\r\n> [\"The only limitation is that an index entry cannot exceed approximately one-third of a page (after TOAST compression, if applicable).\"](https://www.postgresql.org/docs/current/btree-intro.html)\r\n\r\nFrom my understanding of the matter, the size is exceeded as a [CachedValue.value](https://github.com/netbox-community/netbox/blob/v3.4-beta1/netbox/extras/models/search.py#L39) may be too large for a B-Tree index row.\n", "before_files": [{"content": "import sys\nimport uuid\n\nimport django.db.models.deletion\nfrom django.core import management\nfrom django.db import migrations, models\n\n\ndef reindex(apps, schema_editor):\n    # Build the search index (except during tests)\n    if 'test' not in sys.argv:\n        management.call_command('reindex')\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        ('circuits', '0041_standardize_description_comments'),\n        ('contenttypes', '0002_remove_content_type_name'),\n        ('dcim', '0166_virtualdevicecontext'),\n        ('extras', '0082_savedfilter'),\n        ('ipam', '0063_standardize_description_comments'),\n        ('tenancy', '0009_standardize_description_comments'),\n        ('virtualization', '0034_standardize_description_comments'),\n        ('wireless', '0008_wirelesslan_status'),\n    ]\n\n    operations = [\n        migrations.AddField(\n            model_name='customfield',\n            name='search_weight',\n            field=models.PositiveSmallIntegerField(default=1000),\n        ),\n        migrations.CreateModel(\n            name='CachedValue',\n            fields=[\n                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),\n                ('timestamp', models.DateTimeField(auto_now_add=True)),\n                ('object_id', models.PositiveBigIntegerField()),\n                ('field', models.CharField(max_length=200)),\n                ('type', models.CharField(max_length=30)),\n                ('value', models.TextField(db_index=True)),\n                ('weight', models.PositiveSmallIntegerField(default=1000)),\n                ('object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='contenttypes.contenttype')),\n            ],\n            options={\n                'ordering': ('weight', 'object_type', 'object_id'),\n            },\n        ),\n        migrations.RunPython(\n            code=reindex,\n            reverse_code=migrations.RunPython.noop\n        ),\n    ]\n", "path": "netbox/extras/migrations/0083_search.py"}, {"content": "import uuid\n\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.db import models\n\nfrom utilities.fields import RestrictedGenericForeignKey\n\n__all__ = (\n    'CachedValue',\n)\n\n\nclass CachedValue(models.Model):\n    id = models.UUIDField(\n        primary_key=True,\n        default=uuid.uuid4,\n        editable=False\n    )\n    timestamp = models.DateTimeField(\n        auto_now_add=True,\n        editable=False\n    )\n    object_type = models.ForeignKey(\n        to=ContentType,\n        on_delete=models.CASCADE,\n        related_name='+'\n    )\n    object_id = models.PositiveBigIntegerField()\n    object = RestrictedGenericForeignKey(\n        ct_field='object_type',\n        fk_field='object_id'\n    )\n    field = models.CharField(\n        max_length=200\n    )\n    type = models.CharField(\n        max_length=30\n    )\n    value = models.TextField(\n        db_index=True\n    )\n    weight = models.PositiveSmallIntegerField(\n        default=1000\n    )\n\n    class Meta:\n        ordering = ('weight', 'object_type', 'object_id')\n\n    def __str__(self):\n        return f'{self.object_type} {self.object_id}: {self.field}={self.value}'\n", "path": "netbox/extras/models/search.py"}], "after_files": [{"content": "import sys\nimport uuid\n\nimport django.db.models.deletion\nimport django.db.models.lookups\nfrom django.core import management\nfrom django.db import migrations, models\n\n\ndef reindex(apps, schema_editor):\n    # Build the search index (except during tests)\n    if 'test' not in sys.argv:\n        management.call_command('reindex')\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        ('circuits', '0041_standardize_description_comments'),\n        ('contenttypes', '0002_remove_content_type_name'),\n        ('dcim', '0166_virtualdevicecontext'),\n        ('extras', '0082_savedfilter'),\n        ('ipam', '0063_standardize_description_comments'),\n        ('tenancy', '0009_standardize_description_comments'),\n        ('virtualization', '0034_standardize_description_comments'),\n        ('wireless', '0008_wirelesslan_status'),\n    ]\n\n    operations = [\n        migrations.AddField(\n            model_name='customfield',\n            name='search_weight',\n            field=models.PositiveSmallIntegerField(default=1000),\n        ),\n        migrations.CreateModel(\n            name='CachedValue',\n            fields=[\n                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),\n                ('timestamp', models.DateTimeField(auto_now_add=True)),\n                ('object_id', models.PositiveBigIntegerField()),\n                ('field', models.CharField(max_length=200)),\n                ('type', models.CharField(max_length=30)),\n                ('value', models.TextField()),\n                ('weight', models.PositiveSmallIntegerField(default=1000)),\n                ('object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='contenttypes.contenttype')),\n            ],\n            options={\n                'ordering': ('weight', 'object_type', 'object_id'),\n            },\n        ),\n        migrations.RunPython(\n            code=reindex,\n            reverse_code=migrations.RunPython.noop\n        ),\n    ]\n", "path": "netbox/extras/migrations/0083_search.py"}, {"content": "import uuid\n\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.db import models\n\nfrom utilities.fields import RestrictedGenericForeignKey\n\n__all__ = (\n    'CachedValue',\n)\n\n\nclass CachedValue(models.Model):\n    id = models.UUIDField(\n        primary_key=True,\n        default=uuid.uuid4,\n        editable=False\n    )\n    timestamp = models.DateTimeField(\n        auto_now_add=True,\n        editable=False\n    )\n    object_type = models.ForeignKey(\n        to=ContentType,\n        on_delete=models.CASCADE,\n        related_name='+'\n    )\n    object_id = models.PositiveBigIntegerField()\n    object = RestrictedGenericForeignKey(\n        ct_field='object_type',\n        fk_field='object_id'\n    )\n    field = models.CharField(\n        max_length=200\n    )\n    type = models.CharField(\n        max_length=30\n    )\n    value = models.TextField()\n    weight = models.PositiveSmallIntegerField(\n        default=1000\n    )\n\n    class Meta:\n        ordering = ('weight', 'object_type', 'object_id')\n\n    def __str__(self):\n        return f'{self.object_type} {self.object_id}: {self.field}={self.value}'\n", "path": "netbox/extras/models/search.py"}]}