2014-09-25 71 views
0

我想通過python manage.py dbshel​​l發佈SQL命令,但是我得到錯誤「CommandError:你似乎沒有' sqlite3'程序已安裝或在您的路徑上「。在python提示符下,我可以導入psycopg2而不會收到任何錯誤,而psycopg2似乎在我的python路徑中。python manage.py dbshel​​l找不到psycopg2,雖然已經安裝並且路徑爲

我想Django和我的settings.py規定 「發動機」: 「django.db.backends.postgresql_psycopg2」

任何幫助將不勝感激,

感謝,朱利安

回答

0

您需要安裝sqlite3的是能夠運行dbshel​​l

安裝源碼程序就可以解決這個問題:

sudo apt-get install sqlite3 
0

當您運行./manage.py dbshell psql or sqlite3此命令假定程序在您的路徑。這將簡單地調用程序名稱。

sqlite3的

從Python本身這麼想的含有sqlite3命令。如果您想從命令行訪問,則必須安裝包含simple command-line實用程序sqlite3的SQLite庫。但沒有安裝庫,您可以創建數據庫服務器,因爲它不需要運行單獨的服務器,而sqlite3本身就是一個基於文本的文件。

如果你正在開發一個簡單的項目或一些你不打算在生產環境中部署,然後使用SQLite

你的情況首先安裝使用sudo apt-get install sqlite3 libsqlite3-dev訪問dbshel​​l sqlite3的。

Postgres的

比較sqlite3這個postgres需要包進行初始化。 postgresql需要postgresql_psycopg2

+0

嗨 - postgres是我最終要使用的數據庫,所以我想堅持,而不是sqlite3。從任何目錄運行psql都能正常工作,所以我想這是在我的PATH上。正如我所提到的,我認爲psycopg2也安裝好了,因爲我可以在python提示符下運行「import psycopg2」而不會出錯。運行./manage.py dbshel​​l psql給出了一個錯誤列表,輸出爲:'output = self.handle(* args,** options) TypeError:handle()只需要1個參數(給出7)'Thanks for your help – 2014-09-26 09:34:17

+0

@JulianJordan你從來沒有在你的問題中提到當運行'dbshel​​l psql'給出錯誤' – 2014-09-26 09:38:48

+0

嗨 - 我不知道,直到你可以在'./manage.py dbshel​​l'結尾指定psql的有用答案,以便本身一直有幫助,因爲在那之前,我一直在得到一個與sqlite3有關的錯誤(大概是默認選項?) – 2014-09-26 09:42:17

0

我認爲dbshel​​l的功能有些混亂。從documentation

Runs the command-line client for the database engine specified in your ENGINE setting, with the connection parameters specified in your USER, PASSWORD, etc., settings.

  • For PostgreSQL, this runs the psql command-line client.
  • For MySQL, this runs the mysql command-line client.
  • For SQLite, this runs the sqlite3 command-line client.

This command assumes the programs are on your PATH so that a simple call to the program name (psql, mysql, sqlite3) will find the program in the right place. There’s no way to specify the location of the program manually.

它沒有如manage.py shelldbshell只是運行配置數據庫的正常外殼,但它記錄你在settings.py的憑據。

這意味着,如果您使用postgresql,則需要安裝psql命令才能使dbshell正常工作。這個命令不是Python的一部分,但帶有postgresql服務器。

爲了說話 - 如果您已安裝的所有設備都是psycopg2,則dbshell命令將不起作用。

+0

嗨 - 我有安裝的psql命令,並運行它給了我postgres提示:用戶名=# – 2014-09-26 10:50:07

+0

請更新與'settings.py'文件的問題。 – 2014-09-26 10:51:50

+0

@BurhanKhalid問題本身還不太清楚..但是現在我們有'TypeError' – 2014-09-26 11:01:47