2010-11-18 28 views
17

truyện ngắn

tôi chạy ./manage.py schemamigration junk_app --initial trên một dự án django hoàn toàn tươi ngay sau khi vừa mới cài đặt Nam (http://south.aeracode.org/), và tôi nhận được lỗi sau:django nam tươi cài đặt -> lỗi: unknow command 'schemamigration'

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

EDIT: tôi có phiên bản 0,7 (nam/init.pyphiên bản =" 0,07")

câu chuyện dài

Dưới đây gần như là một bản sao đen/paste về những gì vừa xảy ra:

$ 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

Bạn đã tải xuống phiên bản nào của miền Nam? 'schemamigration' không xuất hiện trong các phiên bản trước. Bạn nhận được gì khi bạn gõ './Manage.py' không có args? –

+0

'lệnh con sẵn: dọn dẹp compilemessages convert_to_south createcachetable createsuperuser dbshell diffsettings dumpdata tuôn inspectdb LoadData makemessages di chuyển reset runfcgi runserver vỏ sql sqlall sqlclear sqlcustom sqlflush.210 sqlindexes sqlinitialdata sqlreset sqlsequencereset startApp startmigration syncdb kiểm tra Tuyên chiến xác ' –

+1

tôi sẽ không khuyên bạn nên sử dụng 'apt-get' cho các loại điều này. Không có gì trong hệ điều hành của bạn phụ thuộc vào miền Nam nên không có lý do gì để buộc bạn vào bất kỳ phiên bản cũ nào được đóng gói cho hệ điều hành của bạn. Sử dụng 'pip' để thay thế. –

Trả lời

8

Có thể bạn đang sử dụng một số phiên bản cũ của phiên bản cũ, 0.6.x hoặc thậm chí 0.5.x. Nếu bạn gõ "./manage.py help", bạn sẽ thấy startmigration (iirc) trên danh sách các lệnh có sẵn.

+1

Ngoài ra, trong 0.7 'startmigration' được chia thành' schemamigration' và 'datamigration'. Không có tương đương thực sự cho 'datamigration' trong các phiên bản trước; bạn phải thực hiện 'startmigration' và sau đó thay thế mã di trú. –

+0

Làm cách nào để biết phiên bản Nam của tôi có? Tôi chỉ thấy tùy chọn bắt đầu khi tôi nhập ./manage.py trợ giúp, nhưng điều đó không có ý nghĩa bởi vì tôi vừa cài đặt qua apt-get trên máy Ubuntu 10 (tôi chưa bao giờ chỉnh sửa tệp nguồn). Làm thế nào tôi có thể có một phiên bản cũ của miền Nam, và làm thế nào để tôi chính thức tìm thấy phiên bản tôi có? –

+0

bắt đầu hoạt động, btw, nhưng tôi vẫn muốn biết phiên bản tôi đang sử dụng. –

4

Thay vì sử dụng gói Ubuntu, hãy sử dụng easy_install hoặc pip để cài đặt miền Nam. Điều này sẽ đảm bảo bạn có phiên bản mới nhất.

35

Có thể bạn chưa thêm 'south' vào danh sách INSTALLED_APPS trong tệp settings.py của bạn.

Dưới đây là một trích dẫn từ 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

Thêm 'south' vào danh sách INSTALLED_APPS đã lưu ngày của tôi :-) Cảm ơn bạn. – Hartmut

+0

Tôi đã thêm ''south',' vào cuối INSTALLED_APPS của tôi và nó vẫn không được nhận ra. Bất kỳ ý tưởng? Tôi đang sử dụng virtualenv trên Windows 7. – aldo

+1

Phần này là muy importante !!! 'Nếu Django dường như không chọn điều này, hãy kiểm tra xem bạn không ghi đè INSTALLED_APPS ở nơi khác và bạn có thể chạy nhập từ miền nam vào bên trong ./manage.py shell không có lỗi.' – nicorellius

1

kiểm tra, mà settings.py nộp bạn sử dụng:

./manage.py shell 
import settings 
settings.__file__ 

bạn có thể thấy trong manage.py, mà cài đặt tập tin Django sử dụng bởi defaul:

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

hoặc bạn có thể sử dụng:

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

thay vì:

$./manage.py schemamigration junk_app --initial 
1

Nếu bạn có các cài đặt của bạn trong một thư mục cài đặt, chắc chắn rằng bạn sử dụng một . và không phải / trong đường dẫn. Ví dụ: ./manage.py schemamigration secretballot --initial --settings=settings.jacob

3

Tôi nghĩ vấn đề này có thể rất khó nắm bắt. Tôi đã dành thời gian đáng kể và sau đó tôi đã tìm ra rằng tôi đã ghi đè INSTALLED_APPS đối với một số thử nghiệm. Doh! Vì vậy, đây là chìa khóa. Hãy chắc chắn thêm south vào cuối INSTALLED_APPS của bạn và nếu bạn ghi đè, hãy kiểm tra điều đó.

Các vấn đề liên quan