2

I am going through the Django tutorial at https://docs.djangoproject.com/en/2.2/intro/tutorial02/

It had said previously that if I use sqlite that I don't need to install anything.

Now, it says, after I migrate, ," 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. "

Am I supposed to have a command line editor for sqlite already or do I need to go fetch something from the web? If the latter, what do I get? If the former, what is the command to start it up?

5
  • 1
    First you have to determine your underlying database. Second I propose to use all-in-one tool dbeaver.io that is able to any modern RDMBS that supports JDBC driver. The queries that you quoted are used to display metadata related to tables. Commented Aug 18, 2019 at 15:10
  • I'd like to use sqlite for now. Commented Aug 18, 2019 at 15:11
  • sqlite.org/cli.html - but I suggest to use GUI tool if you are new to RDBMSes Commented Aug 18, 2019 at 15:12
  • If you don't already have sqlite3 on your computer, versions for a few OSes can be downloaded at sqlite.org/download.html (or get the source and build it yourself) Commented Aug 18, 2019 at 21:58
  • The tutorial just tells you how you can verify in the database that everything was done correctly. If you run migrate and everything worked, you don't need to do that. But if you're a database guy, you'll like to see the actual changes that were made to the db after you run migrate. In your terminal just type sqlite3 /path/to/db.sqlite and then you can run sql commands directly on your db. Commented Aug 19, 2019 at 10:06

3 Answers 3

1

It looks like you already have everything installed.

In your terminal, just type sqlite3 to start the sqlite command-line tool. Then use .help to see all the available commands. You can .open your database or you can run sqlite3 /path/to/db.sqlite directly to run the tool with your django db already open.

With the command .schema you'll be able to see all your tables structure. But you can also directly run a sql command like SELECT * FROM polls_question;

Sign up to request clarification or add additional context in comments.

5 Comments

sqlite3 is unrecognized, so it isn't installed or the path is not set.
It's installed somewhere otherwise django wouldn't be able to create a SQLite database and migrate it. What OS are you on?
Windows 10 64 bit
So, it isn't installed by default and i have to download the command line interface?
It's probably installed somewhere but not in your path ($Env:Path)
1

I figured it out. on windows :

  1. download sqlite-tools (there is separate sqlite-tools for each OS. download based on your OS.) from : https://www.sqlite.org/download.html
  2. put 3 .exe files in : C:\Program Files\sqlite3
  3. add C:\Program Files\sqlite3 to windows PATH ENV Variable. (click if you don't know how)
  4. you may now open command prompt and run:

cd <DjangoProjectPath>

sqlite3 db.sqlite3

Inside sqlite shell: .schema

Now it works without any error.

1 Comment

anybody would know how to do on ubuntu ?
0

You can use python manage.py dbshell to launch the cli. Then type .tables to see the tables installed by Django.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.