【问题标题】:Django South migration errorDjango South迁移错误
【发布时间】:2012-08-06 15:03:53
【问题描述】:

我在尝试应用第一次南迁移时遇到错误。我尝试了各种建议(例如删除迁移文件夹中的 .pyc 文件,转换应用程序以及尝试重新启动它,其他小提琴)。有人可以在这里建议我可以做什么吗?谢谢

(env)~/code/django/ssc/dev/ssc/ssc> python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 108, in handle
    ignore_ghosts = ignore_ghosts,
  File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 166, in migrate_app
    Migrations.calculate_dependencies()
  File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 228, in calculate_dependencies
    migration.calculate_dependencies()
  File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 362, in calculate_dependencies
    for migration in self._get_dependency_objects("depends_on"):
  File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 342, in _get_dependency_objects
    for app, name in getattr(self.migration_class(), attrname, []):
  File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 314, in migration_class
    return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py convert_to_south crewcal
This application is already managed by South.
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py migrateTraceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 108, in handle
    ignore_ghosts = ignore_ghosts,
  File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 166, in migrate_app
    Migrations.calculate_dependencies()
  File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 228, in calculate_dependencies
    migration.calculate_dependencies()
  File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 362, in calculate_dependencies
    for migration in self._get_dependency_objects("depends_on"):
  File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 342, in _get_dependency_objects
    for app, name in getattr(self.migration_class(), attrname, []):
  File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 314, in migration_class
    return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'

【问题讨论】:

  • 您是否真的创建了迁移? python manage.py schemamigration --initial
  • 你看到了吗:south.aeracode.org/ticket/819
  • 代码在特定的迁移甚至特定的应用程序上都没有失败——它永远不会走那么远。要么你的 South 包有问题,要么你有某种令人毛骨悚然的现成项目结构。尝试删除并重新安装 South,如果您对模型或应用程序的布局方式有任何异常,请在您的问题中注明。
  • 愚蠢的问题(发生在我身上一次):迁移文件夹中有 init.py 文件吗?
  • 再次重新安装,一切正常。摆弄的事情。感谢您的关注。

标签: django django-south


【解决方案1】:

可能有点晚了,但还是... 您的迁移包中是否有任何其他包(带有__init__.py 的文件夹)并且它会干扰结构?

【讨论】:

  • 我做了scp hostname:/remote/path/to/app/migrations /local/path/to/app/migrations/。然后我在添加了一些迁移之后又做了一次,只不过这次因为migrations文件夹存在,scp把第二个副本放在里面。
【解决方案2】:

在我的情况下,AttributeError: 'module' object has no attribute 'Migration' 错误只是我的迁移文件夹中有一个额外的 .py 文件。

我的迁移目录中有一个额外的实用程序模块,导致 South 阻塞。将模块移动到不同的目录(在我的应用程序迁移目录之上)解决了我的问题。

【讨论】:

  • randlet,是的,你是对的,迁移文件夹中有额外的 .py 文件,我删除了它们,现在它可以正常工作了。
  • 就我而言,我刚刚删除的迁移文件夹中有一个 init.py 文件
【解决方案3】:

哇。我收到 AttributeError: 'module' object has no attribute 'Migration' 错误,原因与上述答案完全不同。

我有一个缩进错误的迁移文件:

class Migration(SchemaMigration):
    def forwards(self, orm):
        # 

    def backwards(self, orm):
        # 
        models = {...}

相对于 ...

class Migration(SchemaMigration):
    def forwards(self, orm):
        # 

    def backwards(self, orm):
        # 

    models = {...}

我不知道为什么会出现这种情况,但是当我修复时错误消失了。

【讨论】:

    猜你喜欢
    • 2015-03-02
    • 1970-01-01
    • 2011-09-28
    • 2013-10-25
    • 2011-08-06
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多