GeoDjango 项目缺少数据库模式中的字段
我创建了一个 Django 项目,使用 PostGIS 后端,据我所知,一切似乎都很好。我现在在该项目中创建了一个应用程序,如下所示:
from django.contrib.gis.db import models
class MyPlace(models.Model):
name = models.CharField(max_length=255)
location = models.PointField()
objects = models.GeoManager()
这应该是名称/点对的简单模型(稍后构建),但数据库不会创建位置字段。没有错误,并且该字段被忽略,直到我尝试访问模型(使用管理员),它发出“DatabaseError:列 myproj_myplace.location 不存在”的声音,
我真的不确定这里出了什么问题,因为那里解析时没有错误(syncdb 工作无异常)。当我为模型运行 sql 命令时,这就是我得到的结果:
BEGIN;
CREATE TABLE "myproj_myplace" (
"id" serial NOT NULL PRIMARY KEY,
"name" varchar(255) NOT NULL
)
;
COMMIT;
再次没有字段!有什么想法吗?
我在 INSTALLED_APPS 中同时拥有“django.contrib.gis”和我的应用程序,并使用 PostGIS 支持构建了我的数据库架构(添加 sql 函数文件方法,而不是模板方法)
提前欢呼以获得任何帮助
这是由空模式,并且表是从头开始创建的
I've created a Django project, using a PostGIS backend, which all seems well as far as I can tell. I've now created an app in this project as follows:
from django.contrib.gis.db import models
class MyPlace(models.Model):
name = models.CharField(max_length=255)
location = models.PointField()
objects = models.GeoManager()
This should be a simple model for a name/point pair (to be built upon later), but the database is not creating the location field. There is no error, and the field is ignored until I try to access the model (using the Admin) where it croaks with "DatabaseError: column myproj_myplace.location does not exist"
I'm really not sure what's going wrong here, since there is no error on parsing (syncdb works without exception). When I ran the sql command for the model, this is what I got:
BEGIN;
CREATE TABLE "myproj_myplace" (
"id" serial NOT NULL PRIMARY KEY,
"name" varchar(255) NOT NULL
)
;
COMMIT;
Again no fields! Any ideas?
I have both 'django.contrib.gis' and my app in my INSTALLED_APPS, and have built my database schema with PostGIS support (adding the sql functions file method, not the template method)
Cheers in advance for any assistance
This is done from an empty schema, and the table is created from scratch
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试“python manage.py sqlall {app}”,由于某种原因,sql 输出不包含空间列,但 sqlall 包含。然后尝试使用 pgadmin3 直接在数据库上运行输出,您可能会更清楚地了解出了什么问题。
Try 'python manage.py sqlall {app}', the sql output doesn't include spatial columns for some reason but sqlall does. Then try running the output directly on the database using pgadmin3, you'll likely get a clearer idea of what's going wrong.
Django 不执行迁移。查看使用
South
进行迁移,或者手动删除表并重新同步以重建表。例如使用mysql删除表和syncdb:
编辑:
哎呀你可能正在使用postgresql。其他人也许能为您提供一个示例,但数据库中现有的 myplace 表仍然是最有可能的问题。
Django doesn't perform migrations. Look at using
South
for migrations, or manually drop the table and resync to rebuild the table.For example using mysql dropping table and syncdb:
edit:
oops you are using the postgresql probably. someone else might be able to give you an example, but an existing myplace table in your database is still the most likely the issue.