當我嘗試使用命令測試任何應用程序時(當我嘗試使用使用此命令的結構部署myproject時,我注意到它):django測試應用程序錯誤 - 創建測試數據庫時出現錯誤:拒絕創建數據庫的權限
python manage.py test appname
我得到這個錯誤:
Creating test database for alias 'default'...
Got an error creating the test database: permission denied to create database
Type 'yes' if you would like to try deleting the test database 'test_finance', or 'no' to cancel
syncdb
命令似乎工作。在settings.py我的數據庫設置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'finance', # Or path to database file if using sqlite3.
'USER': 'django', # Not used with sqlite3.
'PASSWORD': 'mydb123', # Not used with sqlite3.
'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
抱歉,我不能早期測試。感謝它的工作。 – Andrius
儘管OP使用了postgresql,但如果您使用的是mysql,則會出現相同的錯誤。您可以使用以下命令修復它:mysql => GRANT ALL ON * *。\ * to django @ localhost;我最初試圖只授予創建...但後來不能選擇或刪除創建的數據庫。這基本上使你的用戶成爲超級用戶,所以要小心。 – mightypile
我嘗試了一下,發現最小的全局特權是 - 數據:SELECT,INSERT,UPDATE,DELETE,結構:CREATE,ALTER,INDEX,DROP,Admin:REFERENCES。不是超級用戶,但仍然非常強大,所以請謹慎使用。 – Scott