首页 > 解决方案 > 为什么我无法对现有的 postgres 数据库表执行 SQL 查询?

问题描述

出于学习目的,我最近在我的 Django 项目中将我的数据库从 SQLite 迁移到了 postgres,并且成功了。

我可以通过以下命令连接到数据库

sudo -u <username> psql -d <DB_name>;

我能够列出包括架构的表:

\d

但是当我尝试查询简单的选择查询时,它给出了以下错误:

select * from public.AUTHENTICATION_userprofile;
ERROR:  relation "public.authentication_userprofile" does not exist
LINE 1: select * from public.AUTHENTICATION_userprofile;

表详细信息:

 Schema |               Name                |   Type   |  Owner
--------+-----------------------------------+----------+----------
 public | AUTHENTICATION_userprofile        | table    | postgres
 public | AUTHENTICATION_userprofile_id_seq | sequence | postgres

请有任何建议。

谢谢

标签: djangopostgresqlsqlite

解决方案


由于您使用大写字母创建了表,因此 Postgres 将对此表区分大小写,您必须在查询中加上双引号:

select * from public."AUTHENTICATION_userprofile";

推荐阅读