I have a Django rest framework API.
I'm trying to access some data from it using PostgreSQL and psycopg2.
import psycopg2
try:
connection = psycopg2.connect(user="*****",
password='*****',
host="127.0.0.1",
port="5432",
database="locations")
cursor = connection.cursor()
postgreSQL_select_Query = "select * from KnownLocations"
cursor.execute(postgreSQL_select_Query)
print("Selecting rows from find_second_gdt_points")
records = cursor.fetchall()
print(records)
except (Exception, psycopg2.Error) as error:
print("Error while fetching data from postgreSQL", error)
finally:
# Closing connection
if connection:
cursor.close()
connection.close()
print("Connection to DB is closed.")
When running the script I get the following error raised:
Error while fetching data from PostgreSQL relation "knownlocations" does not exist
LINE 1: select * from KnownLocations
But when printing the DB in the terminal the table does exist.
locations=# \dt
List of relations
Schema | Name | Type | Owner
--------+----------------------------------+-------+-------
public | KnownLocations | table | yovel
public | auth_group | table | yovel
public | auth_group_permissions | table | yovel
public | auth_permission | table | yovel
public | auth_user | table | yovel
public | auth_user_groups | table | yovel
public | auth_user_user_permissions | table | yovel
public | authtoken_token | table | yovel
public | django_admin_log | table | yovel
public | django_content_type | table | yovel
public | django_migrations | table | yovel
public | django_session | table | yovel
public | find_second_gdt_points | table | yovel
public | threelocationstrian_locationinfo | table | yovel
(14 rows)