configure Django db setting
Configure the Django Database Settings
Next, we need to specify PostgreSQL as our database in the settings file. As this is the local database, we need to redefine the DATABASES variable in the testing and developing settings files. Edit both files, settings/developing.py and settings/testing.py and add:
try:
db_pass = os.environ["DB_PASS"]
except KeyError:
print("Error: environment variable DB_PASS must be set.")
exit(1)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'db_name',
'USER': 'user_name'
'PASSWORD': db_pass,
'HOST': '',
'PORT': '',
}
}
CREATE DATABASE db_name;
CREATE USER user_name;
ALTER USER user_name WITH PASSWORD 'mypassword';
ALTER ROLE user_name SET client_encoding TO 'utf8';
ALTER ROLE user_name SET default_transaction_isolation TO 'read committed';
ALTER ROLE user_name SET timezone TO 'EST’;
GRANT ALL PRIVILEGES ON DATABASE db_name TO user_name;
Ok, now we are ready to check and sync and migrate our database:
$ python manage.py check
$ python manage.py makemigrations
$ python manage.py migrate
You only need to migrate the database in one environment (developing or testing). This is because the migration is applied to the database, which is the same for both of them.
$ python manage.py createsuperuser
相關文章
- django setting 配置資料庫Django資料庫
- django.db.utils.IntegrityErrorDjangoError
- Oracle DB OS Install and Configure Requirements Quick Reference (8.0.5 to 11.2)OracleUIREM
- sendmail settingAI
- Django提示mysql版本過低:django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.26).DjangoMySqlErrorUI
- SMART Goal SettingGo
- Configure Client Failover For Dataguard Connections Using DB Services-1429223.1clientAI
- django模板報錯:Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either defineDjango
- Procedure for Setting Partner FunctionsFunction
- 阿里雲setting阿里
- Django2.0-db(12)-根據已有的表自動生成模型Django模型
- rman configure
- ASM Setting Larger AU SizesASM
- SAPGUI for Java Connect settingGUIJava
- Xcode的build settingXCodeUI
- Setting the Database Time Zone (80)Database
- vue2 setting配置Vue
- set autotrace on [configure]
- ./configure 幫助
- “setting.xml” has syntax errorsXMLError
- 【Basis】HANA Database SR Basis SettingDatabase
- Docker proxy setting ubuntu 14.04DockerUbuntu
- Mac address setting For RedhatMacRedhat
- raspberry pi bookworm setting static ipWorm
- docker install and configureDocker
- configure shared serverServer
- mysql configure 引數MySql
- rman:configure exclude for tablespace ...
- configure net card in Solaris
- Xenomai-2.6.0-configureAI
- Setting file visibility under MacOSXMac
- Setting REMOTE_LOGIN_PASSWORDFILE (45)REM
- maven setting.xml中出現{DESede}MavenXML
- rlwrap ./configure報錯configure: WARNING: No termcap nor curses library found
- PostgreSQL DBA(156) - pgAdmin(Rollback setting)SQL
- 應用設定Setting的實現
- git (v2.18.0) error setting certificateGitError
- Requested setting INSTALLED_APPSAPP