PostgreSQL+Django+South的第一步



Hi-Stackoverflow人员,

过去,我总是使用sqlite作为数据库平台在本地开发我的Django项目。现在,我想转到PostgreSQL来利用GIS功能,但这一转变让我非常难过。

我安装了类似于本文的postgresql,然后按照GeoDjango的描述创建数据库。

此外,我用替换了模型类

from django.contrib.gis.db import models

并添加

geolocation = models.PointField(_('Geo Location'), 
                geography=True, 
                help_text=_('Geolocation with Longitude and Latitude'))
objects = models.GeoManager()

现在,在深入研究postgreSQL领域之前,我想通过Django Admin测试模型访问,但我遇到了第一个错误。

当我在Admin中选择模型(我刚刚如上所述进行了修改)时,我会得到以下错误:

**InternalError at /admin/remap/project/**
current transaction is aborted, commands ignored until end of transaction block 

这个错误与一个错误的sql查询有关,但我很惊讶Django Admin创建了错误的sql语句(被数百万开发人员使用,在早期的sqlite配置中运行良好)。

当我检查django-sql语句时,我可以看到PointField的条目

"geolocation" geography(POINT,4326) NOT NULL,

但是当我检查psql\d项目时,我看不到对PointField的更改(这应该是导致错误的原因)。由于我在使用South,我执行了

./manage.py schemamigration projects --initial
./manage.py migrate projects

但是我收到的消息

Running migrations for projects:
- Nothing to migrate.
- Loading initial data for projects.

我如何说服souther/postgresql有东西需要迁移?你认为从SQLite到PostgreSQL的转换还有其他问题吗

谢谢你的回答&帮助

一个可能的答案:

你同步数据库了吗?通常,当我在使用south时遇到问题时,我只是删除数据库并从头开始运行manage.py syncdb,以确保我的所有列都在一行中。如果你想让south忽略支持迁移的应用程序,只将数据库同步到当前版本,你可以使用manage.py syncdb --all

最新更新