简体   繁体   English

在PC中找到Django数据库

[英]Find Django Database in the PC

I am trying to create a django project and I created a simple model and ran the django server, entered the fields. 我正在尝试创建django项目,并且创建了一个简单模型并运行django服务器,并输入了字段。 I can see all the data on the django server. 我可以在django服务器上看到所有数据。 I was wondering if there is any other way to see the data entered. 我想知道是否还有其他方法可以查看输入的数据。 在此处输入图片说明

This is the data I entered. 这是我输入的数据。 Can I view it anywhere else in tabular form or database form? 我可以以表格形式或数据库形式在其他任何地方查看它吗?

This is what I do in command window: 这是我在命令窗口中所做的:

sqlite3  db.sqlite3

followed by 其次是

.tables

Where db.sqlite3 is the file that was created when I migrated. 其中db.sqlite3是我迁移时创建的文件。 I am not sure if the data I entered on django server is in this file. 我不确定在django服务器上输入的数据是否在此文件中。 Thanks in advance. 提前致谢。

EDIT 编辑

This is my models.py: 这是我的models.py:

class Site(models.Model):
    # Site ID
    siteID = models.CharField(max_length=255, null=False)
    # End Device ID
    edevID = models.CharField(max_length=255, null=False) 

After running python manage.py runserver I am directed to the django page where I enter the following data 运行python manage.py runserver我被定向到django页面,在其中输入以下数据 在此处输入图片说明

And I save this. 我保存这个。 My question is how can I access this saved data in a database. 我的问题是如何访问数据库中保存的数据。 I tried what you recommended Satya, it only shows me the superuser id. 我尝试了您推荐的Satya,它仅显示超级用户ID。

I hope the question is clear now. 我希望这个问题现在已经清楚。

The question doesn't give enough information as to what you're trying to look for. 该问题无法提供有关您要查找的内容的足够信息。 I am assuming that you want more information out of the tables you've created and that you are using the default sqlite3 database. 我假设您想从已创建的表中获取更多信息,并且您正在使用默认的sqlite3数据库。 In your models.py file, you can use the special __str__ method to make your objects more descriptive 在您的models.py文件中,您可以使用特殊的__str__方法使您的对象更具描述性

def __str__(self):
    return self.title #if your using 'title' as the attribute to identify your objects

Also, enter this command in cmd 另外,在cmd中输入此命令

python manage.py shell

and then in the shell, import the Model whose database you want to view for eg 然后在外壳中,导入要查看其数据库的模型,例如

>>> from django.contrib.auth.models import User
>>> User.objects.all()

This will display all the data associated with your table. 这将显示与表关联的所有数据。 Unfortunately, not in tabular form. 不幸的是,不是表格形式。 You can aso use the command python manage.py inspectdb to view all the classes associated with all tables. 您也可以使用命令python manage.py inspectdb查看与所有表关联的所有类。 To view in proper tabular form, you might need phpmyadmin . 要以正确的表格形式查看,您可能需要phpmyadmin

You can install this software. 您可以安装此软件。 After installation, select your sqlite and see your complete database. 安装后,选择您的sqlite并查看完整的数据库。

DB Browser for SQLite

Download from here: DB Browser 从此处下载: 数据库浏览器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM