4

I'm teaching myself django. At this site

https://docs.djangoproject.com/en/1.11/intro/tutorial02/

It says

If you’re interested, run the command-line client for your database and type \dt (PostgreSQL), SHOW TABLES; (MySQL), .schema (SQLite), or SELECT TABLE_NAME FROM USER_TABLES; (Oracle) to display the tables Django created.

I really don't know what that means. Do they want me to input some commands in the terminal? If so what commands?

fred russell
  • 307
  • 2
  • 11
  • "Run the command-line client for your database". Look it up in the manual of whatever database you're using. – JJJ Nov 04 '17 at 20:24
  • 1
    Possible duplicate of [Show tables in PostgreSQL](https://stackoverflow.com/questions/769683/show-tables-in-postgresql) – AKX Nov 04 '17 at 20:24
  • 4
    Not sure why this question got downvoted. I think PO stated his/her question quite clearly. I think sometimes StackOverflow is too harsh to beginners. – CodingNow Aug 25 '18 at 17:34
  • @AKX Related but not a duplicate. Goal of OP is not to show all tables, but to understand what the \dt command will accomplish in the first place. – Christian Perry Jul 28 '20 at 21:58

2 Answers2

5

This is not a Django or Python function, it is a PostgreSQL one. If you don't use PostgreSQL, this is not relevant to you.

If you do use PostgreSQL and would like to know more about its command-line client, you should check out the official documentation: basically, it is a program that will allow you to connect to your database and issue SQL commands (such as SELECT ..., UPDATE ...) directly, as well as a few non-SQL additions such as listing all tables (\dt), list view (\dv), or exit (\q).

Other SQL systems have their own version of those non-SQL commands, for example MySQL uses SHOW TABLES;, and SQLite3 uses .tables. Use the correct one for your system.

remram
  • 4,805
  • 1
  • 29
  • 42
1

\dt lists all tables in a PostgreSQL database.

The command is run within psql, the command-line tool installed with Postgres.

Here are the steps to run \dt successfully. (Note that Steps 1 and 2 aren't necessary but may be helpful for learning purposes):

  1. Access psql from your terminal by typing psql -U postgres. This allows you to access the psql CLI with access to all local databases.
  2. Input \l to list all local databases
  3. Input psql db_name to access a particular database
  4. Input \dt - this will show all the tables in the database

If you already know the name of the database you can simply type psql db_name from the terminal and \dt thereafter.

Christian Perry
  • 161
  • 1
  • 11