南迁移错误:django.contrib.auth 的 NoMigrations 异常
我在我的项目中使用 South 一段时间了,但最近我做了大量的开发并更改了开发机器,我认为这个过程中出现了一些问题。该项目运行良好,但我无法应用迁移。每当我尝试应用迁移时,我都会得到以下回溯:
danpalmer:pest Dan$ python manage.py migrate frontend
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/management/commands/migrate.py", line 102, in handle
delete_ghosts = delete_ghosts,
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/__init__.py", line 182, in migrate_app
applied = check_migration_histories(applied, delete_ghosts)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/__init__.py", line 85, in check_migration_histories
m = h.get_migration()
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/models.py", line 34, in get_migration
return self.get_migrations().migration(self.migration)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/models.py", line 31, in get_migrations
return Migrations(self.app_name)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/base.py", line 60, in __call__
self.instances[app_label] = super(MigrationsMetaclass, self).__call__(app_label_to_app_module(app_label), **kwds)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/base.py", line 88, in __init__
self.set_application(application, force_creation, verbose_creation)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/base.py", line 159, in set_application
raise exceptions.NoMigrations(application)
south.exceptions.NoMigrations: Application '<module 'django.contrib.auth' from '/Library/Python/2.6/site-packages/django/contrib/auth/__init__.pyc'>' has no migrations.
我对南方没有那么丰富的经验,而且我以前没有遇到过这个错误。我可以在网上找到的关于此错误的唯一有用的提及是针对 0.7 之前的版本,我认为我在 South 0.7 上。我运行“easy_install -U South”只是为了确定。
I have been using South on my project for a while, but I recently did a huge amount of development and changed development machine and I think something messed up in the process. The project works fine, but I can't apply migrations. Whenever I try to apply a migration I get the following traceback:
danpalmer:pest Dan$ python manage.py migrate frontend
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/management/commands/migrate.py", line 102, in handle
delete_ghosts = delete_ghosts,
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/__init__.py", line 182, in migrate_app
applied = check_migration_histories(applied, delete_ghosts)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/__init__.py", line 85, in check_migration_histories
m = h.get_migration()
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/models.py", line 34, in get_migration
return self.get_migrations().migration(self.migration)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/models.py", line 31, in get_migrations
return Migrations(self.app_name)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/base.py", line 60, in __call__
self.instances[app_label] = super(MigrationsMetaclass, self).__call__(app_label_to_app_module(app_label), **kwds)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/base.py", line 88, in __init__
self.set_application(application, force_creation, verbose_creation)
File "/Library/Python/2.6/site-packages/South-0.7-py2.6.egg/south/migration/base.py", line 159, in set_application
raise exceptions.NoMigrations(application)
south.exceptions.NoMigrations: Application '<module 'django.contrib.auth' from '/Library/Python/2.6/site-packages/django/contrib/auth/__init__.pyc'>' has no migrations.
I am not that experienced with South and I haven't met this error before. The only helpful mention I can find online about this error is for pre-0.7 I think and I am on South 0.7. I ran 'easy_install -U South' just to make sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
把这个留给未来的谷歌用户,
我最近在我自己的一个应用程序中遇到了这个例外,而不是一个贡献的应用程序。
经过一番挠头之后,我注意到不知何故该文件……
已被删除,这意味着 python 无法将目录导入为模块等。
Leaving this here for future googlers
I recently ran into this exceptions with one of my own apps today, not a contrib one.
After a bit of head-scratching I noticed that somehow the file ...
... had been deleted, which means python cant import the dir as a module etc etc.
我解决了这个问题。
显然,您不能使用 South 为 Django 一部分的应用程序(例如“auth”)进行迁移,所以我不知道它为什么要这样做。
我意识到有一段时间我的项目中有另一个名为 auth 的应用程序。我一定是在重命名之前尝试过迁移它,因此把它搞砸了。
我从该应用程序的数据库中删除了迁移历史记录条目,一切都很好。
I solved the problem.
Obviously, you can't use South to do the migrations for the apps that are part of Django, like 'auth' so I didn't know why it was trying to.
I realised that for a while I had another app within my project called auth. I must have tried to migrate this at some point before renaming it and therefore messed it all up.
I removed the migration history entries from the database for that app and everything was fine.
我刚刚在切换分支和应用程序版本后遇到了这个问题,并决定从 South_migrationhistory 表中删除现在没有迁移的应用程序
I just ran into this after swithcing branches and app versions, and decided to remove the app that now had no migrations from the south_migrationhistory table
我也遇到了同样的问题,最后我通过删除 South_migrationhistory 表中的所有行并从终端运行以下命令来解决此问题。
这个答案解释了如何重置南迁历史。
编辑:
从 Django 1.5 开始,
reset
命令将不起作用。相反,您必须使用flush
。要了解有关flush功能的更多信息,请阅读此stackoverflow答案。
I also had the same problem, and at the end I fixed this by deleting all rows from south_migrationhistory table and run the following command from terminal.
This answer explain about how to reset south migration history.
Edit:
From Django 1.5 onwards
reset
command won't work. Instead you have to useflush
.To understand more about what flush will do read this stackoverflow answer.
我也遇到了同样的问题,但是这发生在根应用程序上。我发现这是由于早期开发的项目根目录中存在空
models.py
造成的。我怀疑项目应用程序也可能会出现这个问题。I also had the same issue, however this happened to the root application. I discovered that this was due to an empty
models.py
in my project root from earlier development. I suspect this issue may arise for project applications also.您可以在内置模块上进行迁移,这对于数据迁移来说绝对有意义,例如,截断所有用户名、删除无效电子邮件等。
对于来自 django.contrib.auth.models 的用户,只需使用: orm['auth.User']
You can do migrations on built-in modules, and it definitely makes sense for data migrations, for example, truncating all usernames, removing invalid emails, et cetera.
In the case of a User from django.contrib.auth.models, simply use: orm['auth.User']
我遇到了同样的错误,但不是针对 django 模块,而是针对属于我的 virtualenv 一部分的模块。我不明白 South 如何为该模块进行迁移,因为它确实没有任何迁移。然后我记得我已经从应该相同的测试环境复制了数据库。但事实证明,另一个环境的模块版本略有不同,确实进行了迁移。
我最终从南迁移历史中删除了有问题的行(因为无论如何它都是一个测试环境)。
I got the same error, but not for a django module, but for a module that was part of my virtualenv. I didn't get how south could have done a migration for that module, since it really didn't have any migrations. Then I remembered I had copied the database from an test env that was supposed to be the same. But it turned out the other env had a slightly different version of the module which did have a migration.
I ended up deleting the offending row from the south migrationhistory (since it was a test env anyway).
我也遇到了类似的问题,django.contrib.admin 不允许我运行迁移。我通过在 settings.INSTALLED_APPS 中禁用 django.contrib.admin 解决了这个问题
I had a similar problem with django.contrib.admin not letting me run my migrations. I solved it by disabling django.contrib.admin in settings.INSTALLED_APPS