cannot create extension without superuser role

前端 未结 6 1442
孤街浪徒
孤街浪徒 2020-12-23 11:12

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

6条回答
  •  不思量自难忘°
    2020-12-23 12:08

    Another way to solve this that is suggested in the django docs

    $ psql 
    > CREATE EXTENSION postgis;
    

    you can log into a database as the superuser and create the extension once. The extension will then be available to your api's db user. When django executes CREATE EXTENSION IF NOT EXISTS postgis postgres will not throw.

    If you are seeing errors when migrating doublecheck you created the extension in the correct database, a sample sesssion

    $ psql
    => \l            - list databases
    => \c   - connect to django db
    => create extension postgis;
    

    you can verify the extension is installed if you see the table spatial_ref_sys

    => \dt
                       List of relations
     Schema |            Name            | Type  |  Owner
    --------+----------------------------+-------+----------
     public | spatial_ref_sys            | table | postgres
    

    for tests I recommend running them against a local dev database and granting the user superuser abilities like > ALTER ROLE SUPERUSER;

提交回复
热议问题