如何在使用PostgreSQL数据库的Django中使用ArrayField?

3
我想在我的Django models.py文件中进行以下导入:
from django.contrib.postgres.fields import ArrayField

我阅读了这份文档https://docs.djangoproject.com/en/dev/ref/contrib/,并在我的settings.py中的INSTALLED_APPS中添加了'django.contrib.postgres',但是当我尝试同步我的数据库或运行服务器时,我收到了“ImportError:没有名为postgres的模块”的错误信息。

我还需要做些什么或安装其他东西吗?django.contrib.postgres是核心分发的一部分,对吧?

这是追溯信息:

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
2个回答

4

django.contrib.postgres 将成为 1.8 版本的一部分。


哦,谢谢。你知道在Django中是否有其他使用PostgreSQL数组的方法吗? - Matúš Bartko

1

幸运的是,有几个非官方的实现可以在Django中使用PostgreSQL数组。其中最值得注意的是djorm-pgarray。另一个选择是django-dbarray,当Django 1.8最终推出时,迁移不应该太困难。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接