1

こんにちは、django-city -fieldと一緒にdjango-citiesを使用して、ユーザー向けの Google マップ入力で地理位置情報を設定しようとしています。モデルをセットアップするために、次のフィールドをモデルに追加しました。

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 に答える