25

我在我的项目中使用 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.

我对 South 没有那么有经验,而且我以前也没有遇到过这个错误。我可以在网上找到有关此错误的唯一有用的提示是针对 pre-0.7,我认为我在 South 0.7。我运行'easy_install -U South'只是为了确保。

4

8 回答 8

43

把这个留给未来的谷歌人

我最近在我自己的一个应用程序中遇到了这个例外,而不是一个贡献者。

经过一番摸索后,我注意到文件以某种方式...

 app/migrations/__init__.py

...已被删除,这意味着python无法将目录导入为模块等。

于 2010-07-07T09:43:50.223 回答
26

我解决了这个问题。

显然,您不能使用 South 为 Django 中的应用程序进行迁移,例如“auth”,所以我不知道它为什么要这样做。

我意识到有一段时间我的项目中有另一个名为 auth 的应用程序。我一定是在重命名之前尝试过迁移它,因此把它搞砸了。

我从该应用程序的数据库中删除了迁移历史条目,一切都很好。

于 2010-05-19T07:54:59.627 回答
11

我只是在切换分支和应用程序版本后遇到了这个问题,并决定从 south_migrationhistory 表中删除现在没有迁移的应用程序

./manage.py dbshell

mysql> SELECT * FROM south_migrationhistory WHERE app_name = 'social_auth';

104 | social_auth | 0001_initial...                                                                   
105 | social_auth | 0002_auto__add_unique_nonce...


mysql> DELETE FROM south_migrationhistory WHERE app_name = 'social_auth';
Query OK, 2 rows affected (0.00 sec)
于 2014-02-07T20:13:00.320 回答
5

我也遇到了同样的问题,最后我通过从 south_migrationhistory 表中删除所有行并从终端运行以下命令来解决此问题。

python manage.py reset south

这个答案解释了如何重置南迁历史。

编辑:

从 Django 1.5 开始reset,命令将不起作用。相反,您必须使用flush.

python manage.py flush

要了解有关 flush 将执行的更多信息,请阅读此stackoverflow 答案

于 2013-06-14T10:38:34.687 回答
1

我也有同样的问题,但是这发生在根应用程序上。我发现这是由于models.py早期开发中我的项目根目录为空。我怀疑这个问题也可能出现在项目申请中。

于 2012-09-01T12:29:20.147 回答
1

您可以在内置模块上进行迁移,这对数据迁移绝对有意义,例如,截断所有用户名、删除无效电子邮件等。

对于来自 django.contrib.auth.models 的用户,只需使用:orm['auth.User']

于 2013-01-04T20:04:30.400 回答
0

我遇到了同样的错误,但不是针对 django 模块,而是针对作为我的 virtualenv 一部分的模块。我不知道南如何为该模块进行迁移,因为它确实没有任何迁移。然后我记得我从一个应该是相同的测试环境中复制了数据库。但事实证明,另一个 env 有一个稍微不同的模块版本,它确实有一个迁移。我最终从南迁移历史中删除了有问题的行(因为它无论如何都是一个测试环境)。

于 2014-01-24T17:16:03.893 回答
0

我遇到了 django.contrib.admin 类似的问题,不允许我运行迁移。我通过在 settings.INSTALLED_APPS 中禁用 django.contrib.admin 来解决它

于 2014-02-12T12:17:02.777 回答