问题
I'm suffering from this error when migrating South (0.7.5) in Django (1.4). I recently changed the Timezone setting to false, i.e. USE_TZ = False to fix another problem. Any ideas? Thanks
~/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:
回答1:
It may be too late, but I don't think it has anything to do with TZ.
Every migration file has a declaration like:
class Migration(SchemaMigration):
...
The AttributeError
comes from not finding this Migration class declared.
Check whether all of your migrations have one like that. Otherwise please provide more details.
回答2:
To second Augusto Men's answer, the error is really about South being unable to find an implementation of Migration
in a migration module. It's a general Python error message:
AttributeError: 'module' object has no attribute 'Migration'
The error is thrown in south.migration.base, now on line 315 (version 0.8.4)
Debug Printout
Unfortunately, python manage.py migrate
doesn't tell you which file is affected. You can help yourself by adding the following code above line 315 in <your-virtualenv>/local/lib/python*/site-packages/south/migration/base.py
. This will tell you which file you have to work on.
print('## MODULE: %s' % str(self.migration()))
Special Case
I had a special case with the AttributeError
showing up for migrations/<some_app>/__init__.py
, which is usually supposed to be just an empty file. The empty file stopped working after I added an empty model file model.py
to my app to trick Django into looking at my app's fixtures
folder (see How to load Django fixtures from all apps?). I believe this is actually a South bug.
Solution
As suggested above, find out which migration module is affected and simply add an empty implementation of a Migration
class to that file, e.g.:
from south.v2 import SchemaMigration
class Migration(SchemaMigration):
def forwards(self, orm):
pass
def backwards(self, orm):
pass
来源:https://stackoverflow.com/questions/10826532/django-south-migration-attributeerror