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
- Django提示mysql版本過低:django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.26).DjangoMySqlErrorUI
- setting.xmlXML
- 阿里雲setting阿里
- Maven setting.xmlMavenXML
- Django2.0-db(12)-根據已有的表自動生成模型Django模型
- vue2 setting配置Vue
- Requested setting INSTALLED_APPSAPP
- Configure innodb 表空間
- Unable to boot ApiServiceProvider configure..bootAPIIDE
- 【Basis】HANA Database SR Basis SettingDatabase
- “setting.xml” has syntax errorsXMLError
- PostgreSQL DBA(156) - pgAdmin(Rollback setting)SQL
- raspberry pi bookworm setting static ipWorm
- 【Autofs】How to Configure Autofs on CentOS 7?CentOS
- ./configure,make,make install的作用
- Install and configure VMware_vSphere 5
- How to Install and Configure VNC on Ubuntu 18.04VNCUbuntu
- git (v2.18.0) error setting certificateGitError
- maven setting.xml中出現{DESede}MavenXML
- groovy-gradle-setting.gradle和sourceGradle
- How to Install and Configure VNC Server in CentOS 7VNCServerCentOS
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embeddedAI
- Mysql 如何更改default collation_connection settingMySql
- 應用設定Setting的實現
- How to configure a Vagrant (Homestead) VM in Phpstorm with Xdebug on MacPHPORMMac
- Use KTPASS instead of adden to configure mssql.keytabSQL
- How to Configure and Run Spyder Python Editor in Virtual EnvironmentsPython
- configure: error: libcurl >= 7.28.0 library and headers are required with suErrorHeaderUI
- 【Mongodb】db.stats() 與 db.serverStats() 與 db.collection.stats()MongoDBServer
- Unity Texture Setting 中 Filter Mode的影響UnityFilter
- A Method of Setting the LiDAR Field of View in NDT Relocation Based on ROIView
- configure: error: libcurl >= 7.28.0 library and headers are required with support for httpsErrorHeaderUIHTTP
- PHP編譯安裝之Configure引數PHP編譯
- Pycharm提示 configure python interpreter原因?怎麼辦?PyCharmPython
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource couldAI
- Python Uses ibm_db connect to DB2PythonIBMDB2
- scrapyd schedule.json setting 傳入多個值JSON