In your models.py file import
from django.contrib.postgres.indexes import GinIndex
In class Meta create your index by your model field -
class Meta:
indexes = [
GinIndex(name='NewGinIndex',fields=['title','keywords','shortDescription','details'])
]
Then run python manage.py makemigrations
and when you run python manage.py migrate
you will get an error like this -
data type character varying has no default operator class for access method "gin"
HINT: You must specify an operator class for the index or define a default operator class for the data type.
Then go to your app -> migrations -> _modelName_giniIndexname.py file
Then in <number>_modelName_giniIndexname.py
file import
from django.contrib.postgres.operations import BtreeGinExtension
And also in operations
list add -
BtreeGinExtension(),
Then you can run migrate. Probably you will get another error some kind of super user issue. To resolve this issue
Login psql by current user via -
sudo -u postgres psql
then ->
postgres-# alter role <user_name> superuser;
this user should be in your database config user profile -
HINT: Must be superuser to create this extension postgres"/>
then ->
postgres-# CREATE EXTENSION btree_gin;
If you want alter super user permission by after login with current user in psql -
postgres-# alter role <user_name> nosuperuser;
exit from database by -
\q
then python manage.py migrate
Thank you...
😇 Read more -
- https://dev.to/siumhossain/solved-valueerror-the-field-adminlogentryuser-was-declared-with-a-lazy-reference-5fm1
- https://dev.to/siumhossain/djangodbutilsprogrammingerror-column-of-relation-appnametable-already-exists-231g
- https://dev.to/siumhossain/how-to-save-model-object-using-only-foreign-keys-id-in-django-rest-framework-572b
- https://dev.to/siumhossain/how-to-serve-media-files-on-django-production-environment-531m
- https://dev.to/siumhossain/how-to-find-if-its-an-insert-or-update-in-the-django-signal-15l3
- https://dev.to/siumhossain/withdraw-and-modify-restriction-in-password-django-application-2c91
- https://dev.to/siumhossain/how-to-create-gin-index-in-django-migration-django-search-1310
Top comments (0)