4

在 Django (1.4) 中向 South (0.7.5) 迁移时,我遇到了这个错误。我最近将 Timezone 设置更改为 false,即 USE_TZ = False 以解决另一个问题。有任何想法吗?谢谢

~/code/django/ssc/dev/ssc/ssc: python manage.py migrate crewcal
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/__init__.py", line 158, in migrate_app
    Migrations.calculate_dependencies()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/base.py", line 227, in calculate_dependencies
    migration.calculate_dependencies()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/base.py", line 355, in calculate_dependencies
    for migration in self._get_dependency_objects("depends_on"):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/base.py", line 335, in _get_dependency_objects
    for app, name in getattr(self.migration_class(), attrname, []):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/base.py", line 307, in migration_class
    return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'
~/code/django/ssc/dev/ssc/ssc: 
4

2 回答 2

4

可能为时已晚,但我认为这与 TZ 无关。

每个迁移文件都有如下声明:

class Migration(SchemaMigration):
    ...

AttributeError原因是没有找到声明的这个迁移类。

检查您的所有迁移是否都有这样的迁移。否则,请提供更多详细信息。

于 2012-12-18T19:17:28.853 回答
1

对于第二个Augusto Men的回答,错误实际上是关于 South 无法Migration在迁移模块中找到实现。这是一般的 Python 错误消息:

AttributeError: 'module' object has no attribute 'Migration'

错误在south.migration.base中抛出,现在在第 315 行(版本 0.8.4)

调试打印输出

不幸的是,python manage.py migrate不会告诉您哪个文件受到影响。您可以通过在<your-virtualenv>/local/lib/python*/site-packages/south/migration/base.py. 这将告诉您必须处理哪个文件。

print('## MODULE: %s' % str(self.migration()))

特例

我有一个AttributeError显示 for的特殊情况migrations/<some_app>/__init__.py,它通常应该只是一个空文件。在我将一个空模型文件添加model.py到我的应用程序以诱使 Django 查看我的应用程序文件夹后,该空文件停止工作fixtures(请参阅如何从所有应用程序加载 Django 固定装置?)。我相信这实际上是一个南方的错误。

解决方案

如上所述,找出受影响的迁移模块并简单地将一个Migration类的空实现添加到该文件,例如:

from south.v2 import SchemaMigration


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

    def backwards(self, orm):
        pass
于 2014-06-28T11:36:57.167 回答