The database uses postgresql10.12, (WINDOWS7 environment)
Use django3.05 + python3.7 + psycopg2 2.84 + pycharm to create a project: mysit5_305, create an application under the project: Article
image 1(Because there can only be one picture, this picture contains all the pictures)
image 2
Modify the database section in settings.py as follows:
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.postgresql’,
‘NAME’: ‘mysit’,
‘HOST’: ‘localhost’,
‘PROT’: ‘5432’,
‘USER’: ‘postgres’,
‘PASSWORD’: ‘abc123’,
}
}
Add the application “Article” in setting.py
Create a database in postgresql: mysit
image 3
Modify Models.py in the application Article as follows:
class Article (models.Model):
t = models.CharField (max_length = 50)
c = models.TextField ()
Perform makemigrations and migrate
Article_article will be generated in postgresql
After we perform a select operation, we find that the table does not exist, but from the visual list we find that the table exists
image 4
After we register this model in the application’s admin.py and open it in the foreground to add data, we found that it can be added
image 5
image 6 database visual interface
The added data can also be found in the database visual interface
But through the statement: select * from Article_article; but an error:
ERROR: relation “article_article” does not exist
image 7
Is there something wrong with this Article_article? Can only be accessed through django?
Why does django3.05 create a postgresql table only django can read and write, there will be problems through SQL statements? Is this a django3.05 bug for postgresql?
But I do: select * from auth_user; can be queried
image 8
I also found an interesting situation: I can also create a table with the same name in the database visual interface. It is said that the postgresql table name is not case sensitive, and the table with the same name cannot be created.
image 9