trouble using PostgreSQL as a db for OpenWISP2

58 views
Skip to first unread message

unracer

unread,
Jul 13, 2019, 4:44:00 AM7/13/19
to OpenWISP
Hi gang,

Using the ansible playbook to deploy OpenWISP2 is perfectly fine.
Customizing the playbook to deploy OpenWISP2 with a PostgreSQL backend leads me to the error AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'

I got some info from:

and I understand that the error comes from departing from default settings in the OpenWISP2 playbook:
engine: "django.contrib.gis.db.backends.spatialite"
name: "{{ openwisp2_path }}/db.sqlite3"
user: ""
password: ""
host: ""
port: ""
options: {}
openwisp2_database:

Any idea how to solve this?

Thanks a lot for your help!

Best,

unracer




Current playbook and the error received in ansible

##playbook.yml
- hosts: openwisp2
  become: "{{ become | default('yes') }}"
  roles:
    - openwisp.openwisp2
  vars:
    openwisp2_default_from_email: "open...@openwisp2.mydomain.org"
    openwisp2_database:
        engine: django.db.backends.postgresql
        name: openwisp2
        user: openwisp2
        password: "mypassword"
        host: "psql01.mydomain.org"
        port: "5432"
        options: {}

##ansible error received

fatal: [openwisp201.mydomain.org]: FAILED! => {"changed": false, "cmd": "./manage.py migrate --noinput", "msg": "stdout: Operations to perform:\n  App
ly all migrations: account, admin, auth, config, contenttypes, geo, openwisp_users, pki, reversion, sessions, sites, socialaccount\nRunning migrations
:\n  Applying geo.0001_initial...\n:stderr: Traceback (most recent call last):\n  File \"./manage.py\", line 10, in <module>\n    execute_from_command
_line(sys.argv)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/core/management/__init__.py\", line 371, in execute_from_command_line\
n    utility.execute()\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/core/management/__init__.py\", line 365, in execute\n    self.f
etch_command(subcommand).run_from_argv(self.argv)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/core/management/base.py\", line 288,
 in run_from_argv\n    self.execute(*args, **cmd_options)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/core/management/base.py\", l
ine 335, in execute\n    output = self.handle(*args, **options)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/core/management/comman
ds/migrate.py\", line 200, in handle\n    fake_initial=fake_initial,\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/db/migrations/exe
cutor.py\", line 117, in migrate\n    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)\n  File \"/opt/
openwisp2/env/lib/python3.6/site-packages/django/db/migrations/executor.py\", line 147, in _migrate_all_forwards\n    state = self.apply_migration(sta
te, migration, fake=fake, fake_initial=fake_initial)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/db/migrations/executor.py\", line
 244, in apply_migration\n    state = migration.apply(state, schema_editor)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/db/migrati
ons/migration.py\", line 122, in apply\n    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)\n  File \"/opt/openwi
sp2/env/lib/python3.6/site-packages/django/db/migrations/operations/models.py\", line 92, in database_forwards\n    schema_editor.create_model(model)\
n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/db/backends/base/schema.py\", line 265, in create_model\n    definition, extra_params
= self.column_sql(model, field)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/db/backends/base/schema.py\", line 157, in column_sql\
n    db_params = field.db_parameters(connection=self.connection)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/db/models/fields/__in
it__.py\", line 673, in db_parameters\n    type_string = self.db_type(connection)\n  File \"/opt/openwisp2/env/lib/python3.6/site-packages/django/cont
rib/gis/db/models/fields.py\", line 105, in db_type\n    return connection.ops.geo_db_type(self)\nAttributeError: 'DatabaseOperations' object has no a
ttribute 'geo_db_type'\
n", "path": "/opt/openwisp2/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin", "state": "absent",
 "syspath": ["/tmp/ansible_django_manage_payload_U1csLu/ansible_django_manage_payload.zip", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linu
x-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/l
ib/python2.7/dist-packages"]}

Ajay Tripathi

unread,
Jul 13, 2019, 5:15:56 AM7/13/19
to OpenWISP
Hi unracer,

For using postgresql, you need to add PostGIS to your database server. PostGIS is a spatial database extender for PostgreSQL. It adds support for geographic objects allowing location queries to be run in SQL.

The django settings would look something like this:
 ```
        engine: django.contrib.gis.db.backends.postgis

        name: openwisp2
        user: openwisp2
        password: "mypassword"
        host: "psql01.mydomain.org"
        port: "5432"
```

And you'll need some additional packages to work with PostGIS, read here: https://docs.djangoproject.com/en/2.2/ref/contrib/gis/install/postgis/


Best, 
Ajay Tripathi

unracer

unread,
Jul 13, 2019, 3:58:20 PM7/13/19
to OpenWISP
Solved! Thanks a lot, Ajay!

Amit Goyal

unread,
Jul 26, 2019, 3:17:26 AM7/26/19
to OpenWISP
Hi 

Can you share all details about PostgreSQL migration in openwisp . I also want to change DB from SQLite to postgresql in openwisp.

Any help would be appreciated. .

Thanks in advance!

On Sunday, July 14, 2019 at 1:28:20 AM UTC+5:30, unracer wrote:
Solved! Thanks a lot, Ajay!

Ajay Tripathi

unread,
Jul 26, 2019, 3:23:25 PM7/26/19
to OpenWISP
Hello,

On Friday, July 26, 2019 at 12:47:26 PM UTC+5:30, Amit Goyal wrote:
Hi 

Can you share all details about PostgreSQL migration in openwisp . I also want to change DB from SQLite to postgresql in openwisp.

If you are using ansible-openwisp2, you can find the options here: https://github.com/openwisp/ansible-openwisp2#role-variables
The database options look like:
  openwisp2_database:
        engine: django.db.backends.postgresql
        name: openwisp2
        user: postgres
        password: ""
        host: ""
        port: ""
        options: {}


Best,
Ajay Tripathi

Amit Goyal

unread,
Jul 29, 2019, 6:15:04 AM7/29/19
to OpenWISP
Thanks Ajay !
Reply all
Reply to author
Forward
0 new messages