85π
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.
9π
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.
- [Django]-How to add custom search box in Django-admin?
- [Django]-Django 2, python 3.4 cannot decode urlsafe_base64_decode(uidb64)
- [Django]-Variable subtraction in django templates
6π
First, run the command below:
python manage.py dbshell
To access sqlite3 command-line client as shown below:
Then, run the command below:
.table
Or run the command below:
.tables
To show all the tables in SQLite as shown below:
Then, run the command below:
.schema --indent store_product
To show the schema of "store_product" table as shown below:
- [Django]-Phpmyadmin logs out after 1440 secs
- [Django]-What's the difference between select_related and prefetch_related in Django ORM?
- [Django]-Django Admin Show Image from Imagefield
4π
You can use the following command to get the sql script for the database created.
python manage.py sqlmigrate app_label migration_name
- [Django]-Django Rest framework, how to include '__all__' fields and a related field in ModelSerializer ?
- [Django]-Django Rest Framework model serializer with out unique together validation
- [Django]-Django URLS, how to map root to app?
1π
You can view your db.sqlite file online.
sqlite Online
Just upload your file there and you can see your tables which are in your db.sqlite file.
- [Django]-Folder Structure for Python Django-REST-framework and Angularjs
- [Django]-Django REST Framework: adding additional field to ModelSerializer
- [Django]-What is the max size of 'max_length' in Django?
1π
Just wanted to add that someone can find the migrations under my_project_name>my_app_name>migrations and usually you pick the one with the biggest number.
Then the command should be like: python manage.py sqlmigrate my_app_name number
- [Django]-Django 1.8 Run a specific migration
- [Django]-RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
- [Django]-Django β FileField check if None