使用 GeoDjango + PostGIS 进行 Django 测试

标签 django unit-testing postgis geodjango

最近我将 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

最佳答案

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

关于使用 GeoDjango + PostGIS 进行 Django 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519371/

相关文章:

django - 在 DRF 和 ReactJS 中实现推送通知

python - 我在settings.py上实现了电子邮件设置,但是当我提交表单时它不起作用

javascript - 如何测试 Angular mat-nav-list 是否包含元素?

scala - 如何创建不调用底层对象构造函数的 ScalaMock stub ?

google-bigquery - 当点在多边形之外时,ST_Within 错误地返回 true

sql - 我可以使用 Postgres 函数在固定大小的旋转矩形内查找点吗?

python - 使用django在模板页面中显示列表值

php - 为什么 PHPUnit 会尝试查找具有测试套件名称的文件?

sql - 触发器postgresql中的距离计算

Django:按月分组后只计算最新的对象