2010-11-18 71 views
17

短篇小說

我後立即安裝新上運行一個完全新鮮的Django項目./manage.py schemamigration junk_app --initial南(http://south.aeracode.org/),我收到以下錯誤:Django的南新安裝 - >錯誤:未知命令「schemamigration」

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

編輯:我有版本1.7(南方/ init.py版本 =」 0.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', '[email protected]'), 
) 

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: [email protected] 
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 
$ 
+1

你下載了哪個南方版本? 'schemamigration'沒有出現在早期版本中。當你輸入'./ manage.py'沒有參數時,你會得到什麼? – 2010-11-18 19:06:48

+0

'可用子命令: 清理 compilemessages convert_to_south createcachetable createsuperuser dbshel​​l diffsettings dumpdata 平齊 inspectdb loaddata makemessages 遷移 復位 runfcgi 的runserver 殼 SQL sqlall sqlclear sqlcustom sqlflush 個sqlindexes sqlinitialdata sqlreset sqlsequencereset 的startApp startmigration 執行syncdb 測試 TESTSERVER 驗證 ' – 2010-11-18 19:13:41

+1

我不建議使用'的apt-GET'對於這樣的事情。您的操作系統中的任何內容都不依賴於南,所以沒有理由將您自己綁定到爲您的操作系統打包的舊版本。使用'pip'代替。 – 2010-11-18 19:29:28

回答

8

您可能正在使用一些舊的南方版本,0.6.x甚至0.5.x.如果輸入「./manage.py help」,則應該在可用命令列表中看到startmigration(iirc)。

+1

另外,在0.7中'startmigration'被分成'schemamigration'和'datamigration'。在早期版本中沒有真正的'datamigration'等價物;您必須執行'startmigration',然後自行更換遷移代碼。 – 2010-11-18 19:09:22

+0

我如何知道我有哪些南方版本?當我輸入./manage.py幫助時,我只能看到啓動遷移選項,但這沒有任何意義,因爲我剛剛通過apt-get在Ubuntu 10機器上安裝(我從未編輯過源文件)。我怎麼能有一個過時的南方版本,我如何正式找到我的版本? – 2010-11-18 19:15:29

+0

startmigration工作,順便說一句,但我仍然想知道我正在使用的版本。 – 2010-11-18 19:16:13

4

而不是使用Ubuntu軟件包,使用easy_installpip安裝南。這將確保您擁有最新版本。

35

您可能沒有在'settings.py'文件的INSTALLED_APPS列表中添加'south'。

下面是http://south.aeracode.org/docs/installation.html#installation-configure

Now you’ve installed South system-wide, you’ll need to configure Django to use it. Doing so is simple; just edit your settings.py and add 'south' to the end of INSTALLED_APPS.

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.

Once South is added in, you’ll need to run ./manage.py syncdb to make the South migration-tracking tables (South doesn’t use migrations for its own models, for various reasons).

+0

將'south'添加到INSTALLED_APPS列表中保存了我的日子:-)謝謝。 – Hartmut 2013-03-15 23:30:37

+0

我在'INSTALLED_APPS'的末尾添加了''south','但仍然無法識別。有任何想法嗎?我在Windows 7上使用virtualenv。 – aldo 2013-09-24 14:27:57

+1

這部分是muy importante !!! '如果Django似乎沒有選擇它,請檢查你是不是覆蓋其他地方的INSTALLED_APPS,並且你可以從./manage.py shell的內部向南運行導入,沒有任何錯誤。 – nicorellius 2014-02-11 22:06:03

1

檢查報價,其中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 
1

如果你有一個設置文件夾的設置,請確保您使用而不是/在路徑中。 例如:./manage.py schemamigration secretballot --initial --settings=settings.jacob

3

我覺得這個問題可能很難理解。我花了相當多的時間,然後我發現我在重寫INSTALLED_APPS進行一些測試。衛生署!所以這是關鍵。請務必在INSTALLED_APPS的末尾添加south,如果您覆蓋它,請檢查。