close

How to view database and schema of django sqlite3 db

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to view database and schema of django sqlite3 db in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to view database and schema of django sqlite3 db?

  1. How to view database and schema of django sqlite3 db?

    I have been stumbling around for an hour aiming to replicate DESCRIBE table inside the Django shell, and think I've cracked it. I hope this is of use to others.

  2. view database and schema of django sqlite3 db

    I have been stumbling around for an hour aiming to replicate DESCRIBE table inside the Django shell, and think I've cracked it. I hope this is of use to others.

Method 1

Goto the folder where the database is and then

sqlite3  db.sqlite3

Then

.tables

or .schema

depending on what you want. Instead of invoking sqlite3 directly you could do

 python manage.py dbshell 

and then type the sqlite commands.

If you are working with a legacy database you can generate Django models for that using the

 python manage.py inspectdb

But please do yourself a favour and get a GUI database client. Life is much easier when you have one.

Method 2

I have been stumbling around for an hour aiming to replicate DESCRIBE table inside the Django shell, and think I’ve cracked it. I hope this is of use to others.

In the Terminal – enter the following commands.

python3 manage.py dbshell
.tables

Find the name of the table you are looking for, then run the following commands:

.header on
.mode column
pragma table_info('table you are looking for');

Do not forget the semicolon in the last instruction.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read