How to view the database and schema of Django sqlite3 DB
Problem:
I am learning the Django framework. So, for learning purposes, I created a simple to-do project by following some youtube tutorials. By default we get sqlite3 as the default database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
Also, you can see I have db.sqlite3 in my Django project:
todo db.sqlite3 env manage.py mysite
I want to view the database and schema but I can not.
So in this article, we are going to learn how to view the database and schema of Django sqlite3 DB.
Solution:
To view the database, first, you need to go to the folder where your database is. You can do this using this:
sqlite3 db.sqlite3
After that, you can either go to the table or schema. For table:
.tables
For schema:
.schema
If you do not want to invoke sqlite3 you can do this:
python manage.py dbshell
Now type the sqlite commands.
If your database is a legacy database you can generate Django models using this:
python manage.py inspectdb
You can get a database easier if you use a GUI database client. It is much easier when you have one.
Hope this solves your problem. If you have any more questions you can comment below.