Once i activate models in django, why can't i query them directly in postgresql pgAdmin UI?

寵の児 提交于 2021-02-07 09:57:53

问题


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',
    }
}

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)

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.

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.

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 ?

Thank you in advance.


回答1:


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

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

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

\dt *.*

This will list all the tables in your database.



来源:https://stackoverflow.com/questions/41360568/once-i-activate-models-in-django-why-cant-i-query-them-directly-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!