probleme with django and postgres interaction

Hello, I have a problem with django and postgres.

This is the context :

I’m currently trying to create a login system using django for the request and the session système and postgres to store the users.

From my systeme i use a form to recover the information of my user, a sql query to see if my user has the right login. But there is a problem, whatever i try there is always a problem to my query.
For mor context here is one of my tries :

 # In the DB :
vna_v2_1=# SELECT * FROM vna_users;
 id | prenom  | nom | admin |                                            motDePasse                                            | 
----+---------+-----+-------+--------------------------------------------------------------------------------------------------+----------------
  1 | Aksel   | C   | t     | 7fd785e85c8fab96f2d6d683cd3439c0b1b91e21891fb9a1c68ff4a1087e13cadecb661bc0c4d77eab215b423be01da7 | 
  2 | Mathieu | P   | f     | test                                                                                             |

-> (The first user have a ashed password and the second doesn’t)

Query :

SELECT * FROM vna_users WHERE prenom='Mathieu' AND nom='P' AND vna_users.motDePasse='test';

-> This is one of the query i’d try

The error is :

LINE 1: ..._users" WHERE prenom='Mathieu' AND nom='P' AND vna_users....
                                                                                                                           
HINT:  Perhaps you meant to reference the column "vna_users.motDePasse".

-> This is the result i always have whatever i change

Other query tha i have try :

vna_v2_1=# SELECT * FROM "vna_users" WHERE 'vna_users.motDePasse'like "tes%" ;
ERROR:  column "tes%" does not exist
LINE 1: ...* FROM "vna_users" WHERE 'vna_users.motDePasse'like "tes%" ;

#####

vna_v2_1=# SELECT * FROM vna_users WHERE motDePasse= 'test';
ERROR:  column "motdepasse" does not exist
LINE 1: SELECT * FROM vna_users WHERE motDePasse= 'test';
                                      ^
HINT:  Perhaps you meant to reference the column "vna_users.motDePasse".

####


na_v2_1=# SELECT * FROM vna_users WHERE vna_users.prenom='Aksel';
 id | prenom |  nom   | admin |                                            motDePasse                                            | 
----+--------+--------+-------+--------------------------------------------------------------------------------------------------+----------------
  1 | Aksel  | C | t     | 7fd785e85c8fab96f2d6d683cd3439c0b1b91e21891fb9a1c68ff4a1087e13cadecb661bc0c4d77eab215b423be01da7 | 
(1 row)

>Solution :

It looks like the column name is case sensitive in the database, but transformed to lowercase in the database driver. See this answer and this one.

You need to quote the column name as you already tried, but you did it wrongly:

Quoting the column name in postgresql works with double quotes, not single quotes.

SELECT * FROM vna_users WHERE "motDePasse"= 'test'

Leave a Reply