How to view database and schema of django sqlite3 db How to view database and schema of django sqlite3 db django django

How to view database and schema of django sqlite3 db


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

please see https://docs.djangoproject.com/en/3.0/ref/django-admin/#django-admin-inspectdb for additional info.

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


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 columnpragma table_info('table you are looking for');

Do not forget the semicolon in the last instruction.


You can use the following command to get the sql script for the database created.

python manage.py sqlmigrate app_label migration_name