在 django 中激活模型后,为什么不能直接在 postgresql pgAdmin UI 中查询它们? [英] Once i activate models in django, why can't i query them directly in postgresql pgAdmin UI?

查看:49
本文介绍了在 django 中激活模型后,为什么不能直接在 postgresql pgAdmin UI 中查询它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Django 很陌生 &到一般的网络编程.所以,我为这个愚蠢的问题道歉.我使用 django 作为 python & 的框架.我已经与我的数据库 Postgresql 建立了连接:

I am very new to Django & to web programming in general. So, I apologize for the silly question. I am using django as a framework with python & I have made a connection with my database, Postgresql :

    DATABASES = {
        'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'testdb',
        'USER': 'postgres',
        'PASSWORD': '****',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

之后我运行了 python manage.py migrate 命令 &它输出一切正常.我还创建了模型:

After that I ran the python manage.py migrate command & it outputted that everything was OK. I have also created models:

class Albums(models.Model):
    artist = models.CharField(max_length=250)
    album_title = models.CharField(max_length=500)
    genre = models.CharField(max_length=100)
    album_logo = models.CharField(max_length=1000)

class Song(models.Model):
    albums = models.ForeignKey(Albums, on_delete=models.CASCADE)
    file_type = models.CharField(max_length=10)
    song_title = models.CharField(max_length=250)

之后我运行命令python manage.py makemigrations,它输出它可以工作.然后,我运行命令 python manage.py migrate &它输出一切正常.

After that I run the commands python manage.py makemigrations, it outputs that it works. Then, I run the command python manage.py migrate & it outputs that everything is ok.

我想知道为什么,当我在 pgAdmin & 中访问数据库时我使用 SELECT * FROM Albums 查询数据,它甚至无法识别关系.

I want to know why, when I go to the database in pgAdmin & I query the data with a SELECT * FROM Albums, it does not even recognize the relation.

这可能不是测试表是否已创建的正确方法,但谁能帮助我并告诉我为什么不在 pgAdmin UI 中创建它们?

This is probably not the right way to test if the tables were created, but can anyone help me out and tell me why they are not created in the pgAdmin UI as well ?

另外,我如何检查表的创建位置?

Also, how can I check to see where the tables are created ?

提前致谢.

推荐答案

表名会有点不同,不会和模型名一样.它将是app_model".所有字符均为小写.在此示例中,您的查询将是:

The table name would be a bit different, it would not be the same as the model name. It would be "app_model". All the characters are lowercase. In this example, your query would be:

SELECT * FROM 'app'_albums

请将app"替换为小写的应用名称

please replace 'app' with your app name in lower case

正如您所说,您是 Web 开发的新手,请尝试

As you said, you are new to web development, try

\dt *.*

这将列出您数据库中的所有表.

This will list all the tables in your database.

这篇关于在 django 中激活模型后,为什么不能直接在 postgresql pgAdmin UI 中查询它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆