前提
- DB: postgresql
- Shellアプリ: Terminal(Mac)
dbshellを使用します
起動
※設定ファイルを環境ごとに使い分けていない場合、--settingsオプションは不要です。
$ python manage.py dbshell --settings <project name>.<settingsファイル名(拡張子なし)>
テーブル一覧表示
dbname=> \dt
List of relations
Schema | Name | Type | Owner
--------+--------------------------------------+-------+------------
public | account_emailaddress | table | diary_user
public | account_emailconfirmation | table | diary_user
public | accounts_customuser | table | diary_user
public | accounts_customuser_groups | table | diary_user
public | accounts_customuser_user_permissions | table | diary_user
public | auth_group | table | diary_user
public | auth_group_permissions | table | diary_user
public | auth_permission | table | diary_user
public | django_admin_log | table | diary_user
public | django_content_type | table | diary_user
public | django_migrations | table | diary_user
public | django_session | table | diary_user
public | django_site | table | diary_user
(13 rows)
指定したテーブルの全レコード表示
※django_siteはテーブル名
dbname=> select * from django_site;
id | domain | name
----+-------------+-------------
1 | example.com | example.com
(1 row)