Django的南迁AttributeError的(Django South migration At

2019-09-17 15:52发布

我从这个错误在Django(1.4)迁移南(0.7.5)时的痛苦。 最近,我改变了时区设置为false,即USE_TZ =假来解决另一个问题。 有任何想法吗? 谢谢

~/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: 

Answer 1:

它可能为时已晚,但我不认为这有什么关系TZ。

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

class Migration(SchemaMigration):
    ...

AttributeError来自没有找到此声明移民类。

检查是否所有的迁移有一个这样的。 否则,请提供更多的细节。



Answer 2:

第二奥古斯托男子的回答,错误实际上是关于南方是无法找到的实现Migration迁移模块中。 这是一个普通的Python错误信息:

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

该错误是扔在south.migration.base ,现在线315(版本0.8.4)

调试打印输出

不幸的是, python manage.py migrate不会告诉你哪些文件受到影响。 您可以通过添加上述行315下面的代码自便<your-virtualenv>/local/lib/python*/site-packages/south/migration/base.py 。 这将告诉你哪些文件,你必须去努力。

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

特例

我与一种特殊情况AttributeError表示开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


文章来源: Django South migration AttributeError