在Django(1.4)中迁移South(0.7.5)时,我遇到了这个错误。我最近将时区设置更改为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:
答案 0 :(得分:4)
可能为时已晚,但我不认为它与TZ有任何关系。
每个迁移文件都有一个声明:
class Migration(SchemaMigration):
...
AttributeError
来自未发现此Migration类的声明。
检查您的所有迁移是否都有这样的迁移。否则请提供更多详细信息。
答案 1 :(得分:1)
要获得第二个Augusto Men的答案,错误实际上是南方无法在迁移模块中找到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
中的第315行上方添加以下代码来帮助自己。这将告诉您必须处理哪个文件。
print('## MODULE: %s' % str(self.migration()))
我有一个特殊情况,AttributeError
显示migrations/<some_app>/__init__.py
,通常应该只是一个空文件。我将空模型文件model.py
添加到我的应用程序后,空文件停止工作,以欺骗Django查看我的应用程序的fixtures
文件夹(请参阅{{3 }})。我相信这实际上是一个南方的bug。
如上所述,找出受影响的迁移模块,只需在该文件中添加Migration
类的空实现,例如:
from south.v2 import SchemaMigration
class Migration(SchemaMigration):
def forwards(self, orm):
pass
def backwards(self, orm):
pass