2013-03-29 37 views
1

我正在開發一個新的Django項目,並且正在關注this tutorial。我在一步「使用南爲數據庫遷移」,試圖運行python manage.py syncdb,和我得到了以下錯誤:在一個新的Django項目中設置南的錯誤

(editorial)[[email protected] editorial (master *)]$ python manage.py syncdb 
Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line 
    utility.execute() 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 272, in fetch_command 
    klass = load_command_class(app_name, subcommand) 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 77, in load_command_class 
    module = import_module('%s.management.commands.%s' % (app_name, name)) 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module 
    __import__(name) 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/management/commands/__init__.py", line 13, in <module> 
    from south.management.commands.syncdb import Command as SyncCommand 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/management/commands/syncdb.py", line 18, in <module> 
    from south import migration 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/migration/__init__.py", line 11, in <module> 
    from south.models import MigrationHistory 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/models.py", line 4, in <module> 
    class MigrationHistory(models.Model): 
    File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/db/models/base.py", line 97, in __new__ 
    new_class.add_to_class('_meta', Options(meta, **kwargs)) 
TypeError: Error when calling the metaclass bases 
    __init__() keywords must be strings 

這裏是我的settings.py文件:https://gist.github.com/pjhoberman/5273653

有沒有應用程序,只是一個空的項目。我猜這是我的一個簡單忽略 - 任何想法?


編輯

從評論:

  • 我沒有任何的模型呢。接下來的教程,我想在做任何模型工作之前先從南開始。

  • 版本:

    • Django的== 1.5.1
    • 南== 0.7.6
  • 如果我在settings.py南註釋掉,我得到這個錯誤:

    $ python manage.py syncdb

    TypeError: Error when calling the metaclass bases __init__() keywords must be strings


EDIT2

我開始了和使用的Django 1.4,和它的作品。

EDIT3

我更新的python 2.7和使用的Django 1.5,這一切工作爲好。

+0

可以分享模型嗎?在模型初始化的過程中可能會有些微不足道的錯誤 – karthikr

+0

看起來他沒有定義任何模型或定製應用程序。 Django/South的哪個版本? –

+0

在'INSTALLED_APPS'中評論'south'然後運行syncdb會得到錯誤? – iMom0

回答

0

南方有很好的文件記錄,我相信你會通過它後明確。

這是教程。

http://south.readthedocs.org/en/0.7.6/tutorial/part1.html

還是讓生活更簡單..

1)下載南部和它添加到您的應用程序目錄。
2)添加 '南' 到安裝的應用程序在settings.py
3)運行執行syncdb
4)$ ./manage.py schemamigration APPNAME --initial
5)$ ./manage.py遷移應用程序的名字

這就是你需要一個非常基本的開始。

+0

謝謝。這並沒有真正回答這個問題,即關於安裝期間收到的錯誤消息。但是,讚賞。 – hookedonwinter

0

這似乎是一個DB配置問題,試試這個。在文件的頂部:

import os 

則:

PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) 
DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(PROJECT_DIR, 'yourdatabasename.db'), 
    } 
} 

最後一個執行syncdb應該做的伎倆。你也可以嘗試「python manage.py reset south」來解決APP中可能出現的問題。如果這不起作用,我建議你開始一個新的問題,以放棄其他錯誤。

原帖:Django setup with sqlite3?

1

我認爲這個問題是你有你的數據庫設置,「〜」字符。嘗試將#coding=utf-8作爲設置的第一行或第二行,並查看發生了什麼。

如果不解決您的問題,對manage.py文件同一目錄這樣更改數據庫文件名之一:

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': 'databasename.sql', 
    } 
} 

我試圖使一個新的環境下該教程您張貼和我有沒問題。但是,當我試圖用一個數據庫名,你試圖(在其名稱中的一個以「〜」)我得到這個錯誤:

(env) [email protected]:/path >$ python manage.py syncdb --noinput 
Syncing... 
OperationalError: unable to open database file 

我敢打賭,標誌是你的問題的根源...告訴我們如果這解決了你的問題!

1

我更新了python到2.7,並使用了django 1.5,它也可以工作。

沒有任何答案能夠真正解決問題,所以我自己回答,因爲現在我不能刪除問題,因爲有獎金。

2

底部的「TypeError」是解決方案。如果您使用低於2.6.5的Python版本,則會從Django 1.5中得到此錯誤。在這個問題上有Django bug reportSO discussion。可以說,錯誤信息並不直觀。

該OP是正確的,沒有答案解決了這個問題。解決方案是:1)將Python升級到2.7,2)將Django降級到1.4。