2015-06-21 117 views
3

當試圖在Django中執行syncdb時,它會失敗並顯示跟蹤回溯。我試過刪除模式並創建一個乾淨的模式。遷移會創建遷移,但不會創建django_migrations之外的任何表。我也刪除了所有現有的pyc文件作爲預防措施,但沒有運氣。它似乎沒有在初始同步時創建任何表格。目前未與任何型號對付多個數據庫我不得不設置與我以前版本的Django(1.5)的出現此錯誤創建的核心表(AUTH,會議等)django.db.utils.ProgrammingError:關係「auth_user」不存在

System check identified some issues: 

WARNINGS: 
?: (1_6.W001) Some project unittests may not execute as expected. 
    HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information. 
System check identified some issues: 

WARNINGS: 
?: (1_6.W001) Some project unittests may not execute as expected. 
    HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information. 
Operations to perform: 
    Synchronize unmigrated apps: oauth2_provider, core, django_admin_bootstrapped, rest_framework_swagger, rest_framework, django_admin_bootstrapped_bootstrap3 
    Apply all migrations: admin, contenttypes, auth, sessions 
Synchronizing apps without migrations: 
    Creating tables... 
    Installing custom SQL... 
    Installing indexes... 
Running migrations: 
    Applying contenttypes.0001_initial... OK 
    Applying auth.0001_initial... OK 
    Applying admin.0001_initial... OK 
    Applying sessions.0001_initial... OK 
Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line 
    utility.execute() 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute 
    output = self.handle(*args, **options) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 533, in handle 
    return self.handle_noargs(**options) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 36, in handle_noargs 
    if not UserModel._default_manager.exists() and options.get('interactive'): 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 92, in manager_method 
    return getattr(self.get_queryset(), name)(*args, **kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 606, in exists 
    return self.query.has_results(using=self.db) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 445, in has_results 
    return compiler.has_results() 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 757, in has_results 
    return bool(self.execute_sql(SINGLE)) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 786, in execute_sql 
    cursor.execute(sql, params) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 81, in execute 
    return super(CursorDebugWrapper, self).execute(sql, params) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute 
    return self.cursor.execute(sql, params) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__ 
    six.reraise(dj_exc_type, dj_exc_value, traceback) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute 
    return self.cursor.execute(sql, params) 
django.db.utils.ProgrammingError: relation "auth_user" does not exist 
LINE 1: SELECT (1) AS "a" FROM "auth_user" LIMIT 1 
+0

您是使用自定義用戶模型還是使用Django默認'auth.User'? –

+1

真奇怪的是我用相同的數據庫做了一個乾淨的項目,遷移工作正常並創建了所有的表......所以這是現有項目中的東西....不管怎樣,初始項目有很多bug它是django 1.5,所以我要擰它,只是把所有的代碼,我已經起來的v1.7。 – whoisearth

+2

我建議按版本升級Django版本。它保持簡單的變化並互相構建。例如,從1.5到1.8,如果相當困難。至少對我來說,從1.5到1.6到1.7到1.8要容易得多。 – FlipperPA

回答

0

之外。升級沒有帶到南部的多個數據庫。最終,我將不得不重新訪問這個網站,以便我可以嘗試遷移,但同時我已經取消了這一點。刪除settings.py中的多個數據庫實例解決了這個問題。

2

我是在Django 1.8,在這裏我使用的是自定義的用戶配置文件有這個問題,我,如文檔中建議,用OneToOneField用戶創建的。

幸運的是,我將用戶配置文件代碼隔離在一個單獨的應用程序中,我稱之爲「配置文件」。

對於我來說,這種解決方法解決了這個問題:

  • 通過禁用settings.py中的「配置文件」應用程序禁用定製的用戶配置文件從INSTALLED_APPS取出
  • 運行python manage.py遷移
  • 重新插入應用程序,重新啓用自定義用戶配置文件。

這肯定是由於在Django的錯誤。

+0

我試過這個,但是當試圖遷移時,我得到以下錯誤:'django.core.exceptions.ImproperlyConfigured:AUTH_USER_MODEL是指沒有安裝的模型'api.User' '我應該刪除這個設置嗎?編輯:不,它保持失敗。任何想法? – vabada

0

我有非常類似的問題。最終我發現並非所有的應用都有遷移。因此,檢查是否所有已安裝的應用程序(Django項目明智)都有models.py文件也有遷移。這解決了我的問題(迫使Django爲特定的應用程序創建遷移),並且還檢查了migrations.swappable_dependency(settings.AUTH_USER_MODEL),已列出並位於遷移依賴關係的第一位。

相關問題