I\'m trying to run unit tests in Django, and it creates a new database. The database has postgis extensions and when I regularly create the database, I use \"CREATE ExTENSIO
You can also install postgis
to the template1
database template which is inherited by default by all newly created database.
$ psql -U postgres -d template1 -c "CREATE EXTENSION postgis;"
All new databases created from this point will have the postgis
extension installed, including Django's test database, unless they specify a different template when creating a database.
If having postgis
installed to all newly created databases is not desirable, you can create a new template, install postgis
in it, and then have Django use this template when creating the test database.
$ createdb template_postgis; # create a new database
$ psql -U postgres -c "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';" # make it a template
$ psql -U postgres -d template_postgis -c "CREATE EXTENSION postgis;" # install postgis in it
Then in Django settings:
...
DATABASES = {
'default': {
...
'TEST': {
'TEMPLATE': 'template_postgis',
},
},
}