About Creating PostgreSQL Extensions in Test Environment
If you are running into permission errors while creating test databases with extensions, such as:
django.db.utils.ProgrammingError: type "vector" does not exist
Then create a database template with the necessary extensions manually:
$ createdb template_with_extensions
$ psql -d template_with_extensions \
-c "CREATE EXTENSION vector;"
$ psql -d template_with_extensions \
-c "CREATE EXTENSION postgis;"
$ psql -d template_with_extensions \
-c "CREATE EXTENSION pg_trgm;"
$ psql -c "UPDATE pg_database \
SET datistemplate = true \
WHERE datname = 'template_with_extensions';"
And then use that template for the database in the test environment settings:
DATABASES["default"]["TEST"] = {
"TEMPLATE": "template_with_extensions"
}
Another way: make the database user superuser.
Tips and Tricks Development Databases Django 6.x Django 5.2 Django 4.2 PostgreSQL PostGIS pgvector pg_trgm
Also by me
Django Messaging
For Django-based social platforms.
Django Paddle Subscriptions
For Django-based SaaS projects.
Django GDPR Cookie Consent
For Django websites that use cookies.