2013-05-14 99 views
1

讓我進一步闡明我想要做的事情。我一直在我的機器上開發我的Django項目。我也將代碼檢查到一個存儲庫中。目前我是唯一的開發者,但其他開發者將加入。他們將從存儲庫檢出代碼並在其機器上運行它。爲了模擬這種情況,我檢查了我的代碼到另一個目錄並創建了一個新的數據庫。我更新了checkout的settings.py以使用新的數據庫。當我執行syncdb重新創建表,我得到這個錯誤:Django:重新創建表格

User Host  Type Privileges  Grant Action 
root localhost global ALL PRIVILEGES Yes  Edit Privileges 

,並從settings.py:

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': 'testproj',    # Or path to database file if using sqlite3. 
     # The following settings are not used with sqlite3: 
     'USER': 'root', 
     'PASSWORD': '****', 
     'HOST': '127.0.0.1',   # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 
     'PORT': '',      # Set to empty string for default. 
    } 
} 

這裏是

$ python -i manage.py syncdb 
DatabaseError: (1146, "Table 'testproj.auth_user' doesn't exist") 
Traceback (most recent call last): 
    File "manage.py", line 13, in <module> 
    execute_from_command_line(sys.argv) 
    File "c:\Users\jpp\Documents\.virtualenvs\django-test\lib\site-packages\dja 
ngo\core\management\__init__.py", line 453, in execute_from_command_line 
    utility.execute() 
    File "c:\Users\jpp\Documents\.virtualenvs\django-test\lib\site-packages\dja 
ngo\core\management\__init__.py", line 392, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "c:\Users\jpp\Documents\.virtualenvs\django-test\lib\site-packages\dja 
ngo\core\management\base.py", line 230, in run_from_argv 
    sys.exit(1) 
SystemExit: 1 

這裏從phymyadmin是我的數據庫設置INSTALLED_APPS:

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    # Uncomment the next line to enable the admin: 
    # 'django.contrib.admin', 
    # Uncomment the next line to enable admin documentation: 
    # 'django.contrib.admindocs', 
    'helloworld', 
) 

因此,我懷疑另一個開發者有這個相同的問題。這是以前必須解決的情況,但我還沒有能夠將Google的正確詞彙放在一起。

+0

請顯示完整的回溯,也是您的數據庫設置(不要忘記在顯示給我們之前更改數據庫的密碼) – 2013-05-14 03:52:27

+0

保持HOST也爲空。還請顯示setup.py的installed_apps – 2013-05-14 06:39:53

+0

好的,當我這樣做時,出現此錯誤:'OperationalError:(2003,「無法連接到'localhost'(10061)」)上的MySQL服務器''。但是,我一直使用HOST作爲127.0.0.1成功用於我的其他項目;本地主機不適合我。 – user2233706 2013-05-14 12:03:59

回答

0

我發現了這個問題。

在我所創造的應用,HelloWorld的,我曾在__init__.py如下:

from django.contrib.auth.models import User 

if User.objects.filter(username="hello").count() == 0: 
    user = User.objects.create_user(username='hello', password='hellotest') 
    user.save() 

當我註釋掉整個if語句,跑執行syncdb,所有的表被重新創建。我猜在創建所有自己的表之前,auth_user,auth_group等。Django可以完成應用程序所需的任何工作。我不確定這是否是由於python進程包或Django中的錯誤/限制造成的。

0

你並不需要創建測試表,Django將做自動

Test db documentation

如果您願意,您可以使用單獨的數據庫進行測試,只需將其添加到您的settings file即可。確保數據庫已創建,但Django自己創建表。

+0

這不是一個「測試」數據庫,而是我創建的另一個數據庫,用於測試當其他人檢出我的代碼時,他們在運行項目時爲他們準備好的表格。我沒有另外一臺機器來測試這個,所以爲了模擬這個場景,我只是將我的代碼簽出到另一個目錄並更改了數據庫的名稱。我創建的數據庫是空的,它不是以「test」開始的。我猜出了偏執狂,當我發佈這個時,我改變了名字。 – user2233706 2013-05-14 12:00:39