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