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 i开发者_运维知识库deas?
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
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 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:
$ mysql -u myprojadmin -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19215
Server version: 5.1.49-1ubuntu8.1 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use myproj;
Database changed
mysql> drop table myproj_myplace;
Query OK, 0 rows affected (0.02 sec)
mysql> exit;
Bye
$ ./manage.py syncdb
Syncing...
Creating tables ...
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.
精彩评论