Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading