Django使用POSTGIS数据库进行测试时出现错误:“没有属性geo_db_type”。

3

我正在尝试使用两个数据库运行我的应用程序的Django测试套件:一个使用Postgres,另一个使用POSTGIS。这是我的DATABASES配置:

'default': {
       'ENGINE': 'django.db.backends.postgresql_psycopg2',
         ...},
'POSTGIS': {
         'ENGINE': 'django.contrib.gis.db.backends.postgis',
         ...}

当我运行python manage.py test app时,提示我删除旧的测试数据库,当我确认是后,出现以下错误:
Destroying old test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/test/runner.py", line 532, in run_tests
    old_config = self.setup_databases()
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/test/runner.py", line 482, in setup_databases
    self.parallel, **kwargs
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/test/runner.py", line 726, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
    run_syncdb=True,
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/__init__.py", line 119, in call_command
    return command.execute(*args, **defaults)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 172, in handle
    self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 285, in sync_apps
    editor.create_model(model)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 235, in create_model
    definition, extra_params = self.column_sql(model, field)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 134, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 636, in db_parameters
    type_string = self.db_type(connection)
  File "/home/ubuntu/yes/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 120, in db_type
    return connection.ops.geo_db_type(self)
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
1个回答

0
  1. 您使用的是哪个版本的Django?
  2. 在进行数据库更改之前,您是否使用了适当的命令来更新数据库和它们之间的关系,例如syncdbmigrate

回答这两个问题将有助于诊断问题。谢谢!


我正在使用django 1.9,不确定你的第二个问题确切的意思是什么。POSTGRES数据库已通过django的迁移层进行更新。这对于包含地理模型的POSTGIS数据库并非必要。django不会知道这两个数据库之间的任何关系。 - Jake
事实证明我误解了你的问题并且读错了它。我的初步想法是它与settings.py文件有关,以及你如何配置你的数据库等等。一些谷歌搜索向我展示了我完全错了,这与单元测试属性有关。当你尝试这里发生的事情时发生了什么?你是否对你的PostgreSQL进行了任何系统范围的更改? - Dheeraj Chand
那看起来像是 MySQL 的问题。我没有对 Postgres 进行任何更改。 - Jake

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