django - Django南迁移SyntaxError地理位置

标签 django geolocation location syntax-error django-south

您好,我想与django-cities一起使用django-location-field来设置面向用户的Google map 输入的地理位置。我在模型中添加了以下字段以进行设置:

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

之后,我进行了schemamigration:
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

如何解决这个语法错误?感谢您的想法!

最佳答案

删除以前的迁移可解决此问题。关于我命名模型字段的方式,但是我不太确定发生了什么...

关于django - Django南迁移SyntaxError地理位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18965633/

相关文章:

javascript - window.location.replace() 无法重定向浏览器

c - 为什么在 C 输入中需要变量的内存位置而不是变量本身的名称?

java - 使用 TelephonyManager 获取 SIM 国家代码 - 如何?

javascript - 如何将相机始终设置在用户地理位置的中心

python - Django 管理代理模型权限 Django 1.11

python - 如何定义一个模型,其字段由 Django 中的数据库以外的其他数据源填充?

python - 使用关键字参数 'post-detail' kwargs' : '{' : 'long-establis 反转 {'slug'

python - 外键关系中 drf 序列化器的最佳实践是什么

iOS 地理定位,当初始化和声明一起发生时代码工作不同

iphone - iPhone应用程序由于后台定位模式而被拒绝