Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

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

I am new to django framework.

I tried to create a simple blog by following djangogirls tutorials.

Here by default we get sqlite3 as default database Engine

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

I tried some ORM queries also, Even performed some row sql queries

At my django project I have this db.sqlite3 file

blog  db.sqlite3  env  manage.py  mysite

My Question: How to knew the schema that django created in this db.sqlite3(I knew mysql where I can see details about each database and tables,so here I just want to know more things in sqlite)

I have sqlite3 in my system and I tried .database command,but it just shows me

seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main 
question from:https://stackoverflow.com/questions/42227778/how-to-view-database-and-schema-of-django-sqlite3-db

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...