How can I use ArrayField in Django with PostgreSQL DB?

I want to make this import in my django models.py:

from django.contrib.postgres.fields import ArrayField

      

I read this documentation https://docs.djangoproject.com/en/dev/ref/contrib/ and I added 'django.contrib.postgres' to my INSTALLED_APPS in settings.py but when I try to sync my db or with run server, I got "ImportError: No module named postgres"

Is there something else I should be doing or installing? django.contrib.postgres is part of the main distribution right?

This is the traceback:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_com
    utility.execute()
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "c:\Python27\lib\site-packages\django\core\management\base.py", line 280, in execute
    translation.activate('en-us')
  File "c:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
    return _trans.activate(language)
  File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
    __import__(name)
ImportError: No module named postgres

      

+3


source to share


2 answers


django.contrib.postgres

will be part of the release 1.8

.



+4


source


Fortunately, there are several unofficial implementations of postgresql arrays in django. One of the more notable ones is djorm-pgarray . Another option is django-dbarray , when Django 1.8 eventually rolls out, the migration shouldn't be too complicated.



+1


source







All Articles