Here are some frequently used commands when developing with Python/Django.
I would like to take this opportunity to thank you for solving the problem by borrowing the wisdom of our predecessors, and I am very sorry to say that I will summarize it here as my own memo.
(Production environment)
(Development environment)
Terminal
$ psql --version
psql (PostgreSQL) 13.1
Terminal
$ psql -U postgres
Password for user postgres:
psql (13.1)
"help"Get help with.
postgres=#
Terminal
postgres=#create database <database name>;
CREATE DATABASE
Terminal
postgres=# \l
Database list
name|owner|encoding|Collation| Ctype(Conversion operator) |Access rights
---------------+----------+------------------+----------+-------------------+-----------------------
postgres | postgres | UTF8 | C | C |
<DB name>| postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(4 lines)
postgres=#
manage.py
exists.-(Premise) Project setting file:
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<Database name>',
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'HOST': '',
'PORT': '',
}
}
Terminal
(venv_<Project name>) $ set DB_USER=<User name>
(venv_<Project name>) $ set DB_PASSWORD=<Password>
Terminal
(venv_<Project name>) $ python manage.py dbshell --settings <database name>.settings
<Database name>=#
Terminal
<Database name>=# \dt
Terminal
<Database name>=# select *from <table name>;
Terminal
<Database name>=# \q
Or
postgres=# \q
[Python/Django] Summary of frequently used commands (1) <Creating virtual environment, project, application>
[Python/Django] Summary of frequently used commands (2)
We will strive to create an application while carefully checking what values are stored in each table in the database.
Recommended Posts