psycopg2.errors.UndefinedColumn: column "source_id_id" of relation "service_approval_domains" does not exist

I have created model in django for my database. After trying to add data to table I got this error: ` lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) psycopg2.errors.UndefinedColumn: column "source_id_id" of relation "service_approval_domains" does not exist LINE 1: …domains" ("domain", "created_at", "retrieved_at", "source_id… ^ I am not really sure where is the problem… Read More psycopg2.errors.UndefinedColumn: column "source_id_id" of relation "service_approval_domains" does not exist

Trying to use Python variable names in psycopg2 queries

I am writing part of a Python program where I query a PostgreSQL table called stockNames and use the results to print information based on user input. stockNames has the following layout: company stockTicker industry Starbucks SBUX Food/Beverage … I also have a series of Python print statements as follows (brief variable assignments shown as… Read More Trying to use Python variable names in psycopg2 queries

Using yield to run code after method of function execution

I’m trying to create a class method that can run some code after its execution. In pytest we have this functionality with fixtures: @pytest.fixture def db_connection(conn_str: str): connection = psycopg2.connect(conn_str) yield connection connection.close() # this code will be executed after the test is done Using this fixture in some test guarantees that connection will be… Read More Using yield to run code after method of function execution

How to write a query correctly to get the date and time in psycopg2?

Good afternoon, faced with such a situation. I wrote a query to get data from postgresql and it outputs the following, i get a list of tuples: [datetime.date(2022, 8, 12), datetime.time(10, 8, 1), ‘object’, ‘Kos’, ‘login’, ‘number’, ‘password’, None, ‘client’, ‘no’, ‘no’, ‘no’, ‘S5’] but I need to turn the date and time into the… Read More How to write a query correctly to get the date and time in psycopg2?

Getting 'TypeError: not all arguments converted during string formatting' in Python PostgreSQL code (other answers not fixing it)

I have read many answers to this same question, but haven’t seen anything that works for me. I have a very basic app just to test things (in app.py and database.py). I’m using ElephantSQL, psycopg2-binary and have checked – the table on ElephantSQL is made from this code, but cannot insert from here. I can… Read More Getting 'TypeError: not all arguments converted during string formatting' in Python PostgreSQL code (other answers not fixing it)