【问题标题】:Django South migration AttributeErrorDjango南迁移AttributeError
【发布时间】:2012-06-05 07:02:01
【问题描述】:

我在 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: 

【问题讨论】:

    标签: django migration django-south attributeerror


    【解决方案1】:

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

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

    class Migration(SchemaMigration):
        ...
    

    AttributeError 来自于没有找到声明的这个迁移类。

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

    【讨论】:

      【解决方案2】:

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

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

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

      调试打印输出

      很遗憾,python manage.py migrate 没有告诉您哪个文件受到影响。您可以通过在&lt;your-virtualenv&gt;/local/lib/python*/site-packages/south/migration/base.py 的第 315 行上方添加以下代码来帮助自己。这将告诉您必须处理哪个文件。

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

      特殊情况

      我遇到了一个特殊情况,AttributeError 出现在 migrations/&lt;some_app&gt;/__init__.py 中,这通常应该只是一个空文件。在我将 empty model 文件 model.py 添加到我的应用程序以诱使 Django 查看我的应用程序的 fixtures 文件夹后,空文件停止工作(请参阅 How to load Django fixtures from all apps?)。我相信这实际上是南虫。

      解决方案

      如上所述,找出受影响的迁移模块,然后将Migration 类的空实现添加到该文件,例如:

      from south.v2 import SchemaMigration
      
      
      class Migration(SchemaMigration):
          def forwards(self, orm):
              pass
      
          def backwards(self, orm):
              pass
      

      【讨论】:

        猜你喜欢
        • 2011-04-03
        • 2014-06-22
        • 2011-09-28
        • 2014-02-21
        • 1970-01-01
        • 2014-12-21
        • 2014-07-30
        • 2015-11-03
        相关资源
        最近更新 更多