1

嗨,我正在尝试将django-citiesdjango-location-field一起使用,以通过面向用户的谷歌地图输入来设置地理位置。我将以下字段添加到我的模型中以进行设置:

class Thing(models.Model):
    city = models.ForeignKey(City)
    location = LocationField(based_fields=[city], zoom=7, default=Point(1, 1), srid=3857)
    objects = models.GeoManager()

之后我运行了架构迁移:

python2.7 manage.py schemamigration myapp --auto
 ? The field 'Thing.city' does not have a default specified, yet is NOT NULL.
 ? Since you are adding this field, you MUST specify a default
 ? value to use for existing rows. Would you like to:
 ?  1. Quit now, and add a default to the field in models.py
 ?  2. Specify a one-off value to use for existing columns now
 ? Please select a choice: 2
 ? Please enter Python code for your one-off default value.
 ? The datetime module is available, so you can do e.g. datetime.date.today()
 >>> 0
 + Added field city on myapp.Thing
 + Added field location on myapp.Thing
Created 0002_auto__add_field_thing_city__add_field_thing_location.py. You can now apply this migration with: ./manage.py migrate myapp

但是在尝试迁移我的应用程序时,我收到了这个错误。但是,我不确定如何解决它:

[myproject]$ python2.7 manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/myapp/lib/python2.7/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/myapp/lib/python2.7/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/myapp/lib/python2.7/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/myapp/lib/python2.7/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/myapp/lib/python2.7/South-0.7.5-py2.7.egg/south/management/commands/migrate.py", line 107, in handle
    ignore_ghosts = ignore_ghosts,
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/migration/__init__.py", line 166, in migrate_app
    Migrations.calculate_dependencies()
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/migration/base.py", line 227, in calculate_dependencies
    migration.calculate_dependencies()
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/migration/base.py", line 358, in calculate_dependencies
    for migration in self._get_dependency_objects("depends_on"):
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/migration/base.py", line 338, in _get_dependency_objects
    for app, name in getattr(self.migration_class(), attrname, []):
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/migration/base.py", line 310, in migration_class
    return self.migration().Migration
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/utils/__init__.py", line 62, in method
    value = function(self)
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/migration/base.py", line 301, in migration
    raise exceptions.BrokenMigration(self, sys.exc_info())
south.exceptions.BrokenMigration: While loading migration  'myapp:0002_auto__add_field_thing_city__add_field_thing_location':
Traceback (most recent call last):
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/migration/base.py", line 297, in migration
    migration = __import__(full_name, {}, {}, ['Migration'])
  File "/myapp/myproject/myapp/migrations/0002_auto__add_field_thing_city__add_field_thing_location.py", line 18
    self.gf('location_field.models.LocationField')(default=<Point object at 0x277eeb0>, srid=3857),
                                                       ^
SyntaxError: invalid syntax

如何修复此语法错误?谢谢你的想法!

4

1 回答 1

0

删除之前的迁移解决了这个问题。关于我命名模型字段的方式,但我不太确定到底发生了什么......

于 2013-09-27T19:56:40.050 回答