15

How can I see my databases in SQlite for Django.

I am following the django tutorial on ubuntu.

Now its working fine except. After running

python manage.py sql polls

then

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    

There is no mysite database. How can i see the database?

4

3 回答 3

19

您的mysite数据库将位于项目根目录中的文件系统本身(django 项目的最顶层文件夹),如果这是您的settings.py样子:-

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 管理员中添加、编辑、删除或查看您的投票数据。

您当然可以mysite在您的 django 项目根目录(顶层文件夹)中加载您的数据库,并使用类似http://sqlitebrowser.sourceforge.net/的方式查看其中的数据

在 ubuntu 终端的命令行中,如果您确实正确执行了 syncdb,您应该会看到类似于以下内容:-

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,如下所示: -

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 shell 中的.tables命令将为您提供:-

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> 
于 2012-11-03T13:04:57.363 回答
12

如果已经同步,我已经使用了选项“dbshel​​l”:

python manage.py dbshell

SQLite 版本 3.8.2 2013-12-06 14:53:30 输入“.help”获取说明 输入以“;”结尾的 SQL 语句

sqlite> .databases

于 2016-06-24T05:51:39.583 回答
0

只需转到您的项目文件夹,那里有 ds.sqlite3 文件

从https://sqlitebrowser.org/在工具中打开它

内部工具 > 浏览数据 > 在下拉列表中选择表格以查看表格

于 2018-10-25T11:29:02.647 回答