I have a flask application that is connected to a postgresql database. My issue is that when I query the database using SQLAlchemy to insert an item, this is what happens:
from sqlalchemy import insert
catInfoString = json.dumps(catInfo)
productsString = json.dumps(products)
stmt = (
insert(Category).
values(catInfo=str(catInfoString), products=str(productsString))
)
I get this error: sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column "catInfo" of relation "category" does not exist
So, I tried to see if catInfo exists with this:
allCatInfo = db.engine.execute("SELECT catInfo FROM Category")
print(allCatInfo)
This worked perfectly. So why is it that I can query this table, but not insert?
Variable outputs
catInfoString
:
{"name": "test", "shortDesc": "cat desc"}
productsString
:
[["test", {"title": "holderProduct", "path": ["Products", "test"], "desc": "product desc"}]]
type(catInfoString)
:
<class 'str'>
type(productsString)
:
<class 'str'>
Case Sensitive
Also, when I try to use `catinfo` instead of `catInfo`, I get this error message:sqlalchemy.exc.CompileError: Unconsumed column names: catinfo
Using `INSERT INTO ...`
I tried using this line instead too...qry = "INSERT INTO Category (catInfo, products) VALUES (%s, %s)" % (str(catInfoString), str(productsString))
db.engine.execute(qry)
However, this did not work either and raised the error below:
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "{"