Flask SQL Error: Undefined Column in sessions Table

Question: I am with girl developing a scientific goal-tracking application named SciHub using Flask. The app is designed to help users reach their academic goals with the aid of a GPT-driven model. Currently, I am encountering an issue during the deployment phase related to the database setup in postgreSQL.

I am seeking guidance on why this error is occurring and how to resolve it. Is there a mismatch between my table definition and how SQL is interpreting it? Any insights or suggestions on how to fix this issue would be greatly appreciated.

  • I set replit’s degugger breakpoins on key lines with code in files

Repl link/Link to where the bug appears:
https://replit.com/@indrad3v4/SciHub-Flask

**Screenshots, links, or other helpful context:
Error Details:



During deployment, the application logs show the following error:
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column sessions.session_id does not exist

This error occurs when the application tries to interact with the ‘sessions’ table, particularly with a column named ‘session_id’.

Here is the relevant part of my model.py file where I define the app_sessions table:

commands = (
    """
    CREATE TABLE IF NOT EXISTS users (
        id SERIAL PRIMARY KEY,
        username VARCHAR(255) UNIQUE NOT NULL,
        password_hash VARCHAR(255) NOT NULL
    );
    """,
    # ... other table definitions ...
    """
    CREATE TABLE IF NOT EXISTS app_sessions (
        id SERIAL PRIMARY KEY,
        session_id VARCHAR(255) UNIQUE NOT NULL
    );
    """
)

Attempts to Resolve:

  • I have double-checked the table creation commands in model.py to ensure they are correctly written.
  • I reviewed the SQLAlchemy documentation for any potential mistakes in defining the table schema.
  • I attempted to redeploy the application after making minor adjustments to the database configuration.

There’s your issue, you declare the table as app_sessions, but you’re trying to read from sessions

1 Like

i think this issue with flask-sessions. because previously i test and
CREATE TABLE app_sessions
and CREATE TABLE sessions with session_id column
now, after your response i back all to sessions instead app_sessions
but issue persists, now when i click Run
i see what i see on screen
and than returns repl error



Screen Shot 2024-01-04 at 10.55.41

some recommendations?

That’s upm errors, try disabling upm’s guessing and installing:

yes, this way overcome dependencies moment, so im continue my debugging, im write here when i deploy scihub of have any q, big thants @Firepup650


e

That looks like the dependencies are still stuck, did you add both of the lines? (And don’t forget to kill 1 afterwards)

yes, but now another situation — all packages are cleaned, and simple os not work;


That shouldn’t be possible, os is a default package. I’d recommend making a new Repl and trying again.

lol, hmmm… it run

so, for real i 2 weeks solve login/dashboard quest — i cant move into dashboard with ai functionality,
so problem with fetching data from db for sucessfull login ;(

now i see
TypeError: cannot use a string pattern on a bytes-like object

but i think it’s something with way how i use flask + buildin postgreSQL in my project
who can support me plz?