问题描述
如何在Django的SQlite中查看我的数据库。
How can I see my databases in SQlite for Django.
我正在关注。
现在可以正常工作了,除了。运行
Now its working fine except. After running
python manage.py sql polls
然后
python manage.py syncdb
所以我想我会检查一下数据库和表,但这是问题所在:
So then I thought I would check out the daabase and tables but this is where the issue is:
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main
1 temp
没有mysite数据库。
如何查看数据库?
There is no mysite database.How can i see the database?
推荐答案
您的 mysite settings.py
的样子,数据库将位于项目根目录(django项目的最顶层文件夹)中的文件系统中:
your mysite
database will be in the file system itself in the root of your project (top most folder of your django project), if this is how your settings.py
looks like:-
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mysite', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
如果启用了django管理员,并编写相应的您的民意调查应用程序的admin.py文件,您应该可以在django admin中添加,编辑,删除或查看您的民意调查数据。
If you enabled your django admin, and write the appropriate admin.py files for your polls app, you should be able to add, edit, delete or view your polls data in django admin.
您当然可以加载自己的在django项目根目录(顶部文件夹)中的 mysite
数据库,并使用
You can of course load up your mysite
database in your django project root (top folder) and view the data in it using something like http://sqlitebrowser.sourceforge.net/
在ubuntu终端的命令行中,如果您正确执行了syncdb,您应该会看到一些东西类似于以下内容:-
In command line in your ubuntu terminal, if you did do your syncdb correctly, you should be seeing something similar to this:-
calvin$ ./manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'calvin'): calvin
E-mail address: myemail@myemail.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
您提到您已经正确运行了 ./ manage.py syncdb
,因此您应该能够访问sqlite数据库通过执行 sqlite mysite
,例如:-
You mentioned you already run your ./manage.py syncdb
correctly, so you should be able access your sqlite database by executing sqlite mysite
, like this:-
calvin$ sqlite3 mysite
SQLite version 3.7.14.1 2012-10-04 19:37:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
然后在sqlite中使用 .tables
命令shell将为您提供:-
And the .tables
command in your sqlite shell will give you:-
sqlite> .tables
auth_group auth_user_user_permissions
auth_group_permissions django_content_type
auth_permission django_session
auth_user django_site
auth_user_groups
sqlite>
这篇关于在终端-django中使用python sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!