【问题标题】:django south fresh install --> error: unknown command 'schemamigration'django south 全新安装 --> 错误:未知命令 'schemamigration'
【发布时间】:2011-05-12 05:38:57
【问题描述】:

短篇小说

我在全新安装 South (http://south.aeracode.org/) 后立即在一个全新的 django 项目上运行 ./manage.py schemamigration junk_app --initial,我收到以下错误:

Unknown command: 'schemamigration'
Type 'manage.py help' for usage.

编辑:我有 .7 版(南/init.pyversion = ".07")

长篇大论

下面几乎是对刚刚发生的事情的字面复制/粘贴:

$ sudo apt-get install python-django-south
$ django-admin.py startproject junk_proj
$ cd junk_proj
$ ./managy.py startapp junk_app
$ vim settings.py #add 'south' to INSTALLED_APPS

.

$ cat settings.py
# Django settings for junk_proj project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

import os
CWD = os.getcwd()
DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = CWD+'/db'             # Or path to database file if using sqlite3.
DATABASE_USER = ''             # Not used with sqlite3.
DATABASE_PASSWORD = ''         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'vgtm!i0*(qn$8m9&0u_)#(5yh(kt8%+4dlwfum%xtt-$1ge+ld'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
#     'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
)

ROOT_URLCONF = 'junk_proj.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'south',
    'junk_app',
)

.

$ ./managy.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table south_migrationhistory

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'foo'): admin
E-mail address: admin@example.com
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model

synced:
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > south
 > junk_app

Not synced (use migrations):
 -
(use ./manage.py migrate to migrate these)
$
$./manage.py schemamigration junk_app --initial
Unknown command 'schemamigration'
Type 'manage.py help' for usage
$

【问题讨论】:

  • 您下载了哪个版本的 South? schemamigration 没有出现在早期版本中。当你在没有参数的情况下输入./manage.py 会得到什么?
  • Available subcommands: cleanup compilemessages convert_to_south createcachetable createsuperuser dbshell diffsettings dumpdata flush inspectdb loaddata makemessages migrate reset runfcgi runserver shell sql sqlall sqlclear sqlcustom sqlflush sqlindexes sqlinitialdata sqlreset sqlsequencereset startapp startmigration syncdb test testserver validate
  • 我不建议使用apt-get 来处理这类事情。您的操作系统中没有任何东西依赖于 South,因此没有理由将自己绑定到为您的操作系统打包的任何旧版本。请改用pip
  • 我也有同样的问题,运行最新版本的南...好像没有安装。

标签: django django-south


【解决方案1】:

您可能尚未将“south”添加到 settings.py 文件的 INSTALLED_APPS 列表中。

这是来自http://south.aeracode.org/docs/installation.html#installation-configure的引述

现在您已经在整个系统范围内安装了 South,您需要配置 Django 使用它。这样做很简单;只需编辑您的 settings.py 和 将 'south' 添加到 INSTALLED_APPS 的末尾。

如果 Django 似乎没有发现它,请检查你是否没有 覆盖其他地方的 INSTALLED_APPS,并且您可以运行 import south 从 ./manage.py shell 内部没有错误。

添加 South 后,您需要运行 ./manage.py syncdb 来生成 South 迁移跟踪表(South 不使用迁移 有自己的模型,出于各种原因)。

【讨论】:

  • 将 'south' 添加到 INSTALLED_APPS 列表中拯救了我的一天 :-) 谢谢。
  • 我在我的 INSTALLED_APPS 末尾添加了'south',,但它仍然无法识别。有任何想法吗?我在 Windows 7 上使用 virtualenv。
  • 这部分很重要!!! If Django doesn’t seem to pick this up, check that you’re not overriding INSTALLED_APPS elsewhere, and that you can run import south from inside ./manage.py shell with no errors.
【解决方案2】:

您可能正在使用一些旧的 South 版本,0.6.x 甚至 0.5.x。如果您键入“./manage.py help”,您应该会在可用命令列表中看到 startmigration (iirc)。

【讨论】:

  • 另外,在 0.7 中,startmigration 被拆分为 schemamigrationdatamigration。在早期版本中,datamigration 没有真正的等价物;你必须做startmigration,然后自己替换迁移代码。
  • 我如何知道我拥有的是哪个版本的 South?当我输入 ./manage.py 帮助时,我只看到 startmigration 选项,但这没有任何意义,因为我只是通过 apt-get 在 Ubuntu 10 机器上安装的(我从未编辑过源文件)。我怎么会有一个过时的 South 版本,我如何正式找到我拥有的版本?
  • startmigration 有效,顺便说一句,但我仍然想知道我正在使用的版本。
  • 要查看您正在使用的版本,在解释器中import south,然后打印south.__version__
  • 也可以在 south/__init__.py 中查看版本
【解决方案3】:

不要使用 Ubuntu 软件包,而是使用 easy_installpip 来安装 South。这将确保您拥有最新版本。

【讨论】:

    【解决方案4】:

    我认为这个问题可能非常难以捉摸。我花了相当多的时间,然后我发现我正在覆盖INSTALLED_APPS 进行一些测试。嗬!所以这是关键。请务必在您的 INSTALLED_APPS 末尾添加 south,如果您覆盖它,也要检查它。

    【讨论】:

      【解决方案5】:

      如果您的设置位于设置文件夹中,请确保在路径中使用 . 而不是 /。 示例:./manage.py schemamigration secretballot --initial --settings=settings.jacob

      【讨论】:

        【解决方案6】:

        检查,您使用的是哪个 settings.py 文件:

        ./manage.py shell
        import settings
        settings.__file__
        

        您可能会在 manage.py 中看到 Django 默认使用的设置文件:

        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
        

        或者你可以使用:

         $./manage.py schemamigration junk_app --settings=settings --initial
        

        代替:

         $./manage.py schemamigration junk_app --initial
        

        【讨论】:

          猜你喜欢
          • 2013-05-09
          • 1970-01-01
          • 2013-05-14
          • 2013-12-13
          • 1970-01-01
          • 1970-01-01
          • 2018-10-09
          • 2012-08-13
          • 1970-01-01
          相关资源
          最近更新 更多