【问题标题】:Django testing using GeoDjango + PostGIS使用 GeoDjango + PostGIS 进行 Django 测试
【发布时间】:2014-04-26 11:53:20
【问题描述】:

最近我将 GeoDjango 添加到我的项目并安装 PostGIS 2.0 来实现它,但是现在当我尝试运行 manage.py test 时,我收到以下错误:

Creating test database for alias 'default'...
Got an error creating the test database: database "test_database" already exists

Type 'yes' if you would like to try deleting the test database 'test_database', or 'no' to cancel: yes
Destroying old test database 'default'...
DatabaseError: type modifier is not allowed for type "geometry"
LINE 24:     "location" geometry(POINT,432

在我的 settings.py 中,我设置了SOUTH_TESTS_MIGRATE = False

感谢您的任何建议。

编辑:

添加有用的输出

./manage.py test --verbosity=3
Creating test database for alias 'default' ('test_database')...
Got an error creating the test database: database "test_database" already exists

Type 'yes' if you would like to try deleting the test database 'test_database', or 'no' to cancel: yes
Destroying old test database 'default'...
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_flatpage_sites
Creating table django_flatpage
Creating table django_session
Creating table django_site
Creating table celery_taskmeta
Creating table celery_tasksetmeta
Creating table djcelery_intervalschedule
Creating table djcelery_crontabschedule
Creating table djcelery_periodictasks
Creating table djcelery_periodictask
Creating table djcelery_workerstate
Creating table djcelery_taskstate
Creating table notification_noticetype
Creating table notification_noticesetting
Creating table notification_noticequeuebatch
Creating table registration_registrationprofile
Creating table south_migrationhistory
Creating table authtoken_token
Creating table social_auth_usersocialauth
Creating table social_auth_nonce
Creating table social_auth_association
Creating table accounts_clientprofile
Creating table locations_location
DatabaseError: type modifier is not allowed for type "geometry"
LINE 24:     "location" geometry(POINT,4326),

数据库配置:

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'database',                      
        'USER': 'database',
        'PASSWORD': 'dbpass',
        'HOST': 'localhost'
    }
}

带有 PointField 的模型:

from django.contrib.gis.db import models
class Location(models.Model):
    user = models.ForeignKey(User)
    name = models.CharField(max_length=100)
    location = models.PointField(blank=True, null=True)

    objects = models.GeoManager()

    def __unicode__(self):
        return self.name

【问题讨论】:

  • 从 1.python manage.py test --verbosity=3 添加有用的输出 2.您的 postgres 日志文件,以及具有位置字段的模型。

标签: django unit-testing postgis geodjango


【解决方案1】:

我认为您的数据库中有一个 db/template template_postgis。见Testing a GeoDjango app with a PostGIS database

【讨论】:

    猜你喜欢
    • 2014-09-03
    • 2021-05-07
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 2018-01-22
    • 1970-01-01
    • 2016-05-14
    相关资源
    最近更新 更多