Django Python manage.py test error, error prompt:
Creating test database for alias ‘postgres’…
Got an error creating the test database: permission
Creating test database for alias ‘postgres’…
Got an error creating the test database: permission
Django Settings:
DBNAME = 'multi_test'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'mysql': {
'ENGINE': 'django.db.backends.mysql',
'NAME': DBNAME,
'USER': 'root',
'PASSWORD': 'xxx',
'HOST': '127.0.0.1',
'PORT': 3306,
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
},
},
'postgres': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': DBNAME,
'USER': 'root',
'PASSWORD': 'xxx',
'HOST': '127.0.0.1',
'PORT': 5432,
},
}
Python manager.py Migrate will work fine
Solutions:
Add createdB access to the PostgresQL database for root (the ‘USER’ corresponding to ‘Postgres’ in Settings)
wenjie@digi007:~/study/dbtest/multi_dbs$ su - postgres
Password:
postgres@digi007:~$ psql
psql (9.6.2)
Type "help" for help.
postgres=# alter user root createdb;
will no longer report an error when you rerun test.