Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not an executable object: 'SELECT * FROM LoanParcel' [duplicate]

I want to use the database by creating it as a dataframe, and I've used sqlalchemy for importing create_engine, but I'm stuck with the not an executable object: 'SELECT * FROM LoanParcel', where LoanParcel is the name of the database I want to create as a dataframe, how should I fix it?

views.py

from sqlalchemy import create_engine

engine = create_engine("mysql+pymysql://mariadb:mariadb@localhost:9051/mariadb")

def user_detail(req, id):
    conn = engine.connect()
    QLoanParcel = "SELECT * FROM LoanParcel"
    dfParcel = pd.read_sql(QLoanParcel, conn)
    conn.close()
    df = dfParcel.drop(["id", "date_add", "start_date"], axis = 1)
    return render(req,'pages/user_detail.html')
like image 299
wanx Avatar asked Sep 08 '26 13:09

wanx


1 Answers

SQLAlchemy 2 introduced breaking changes, you need to wrap your SQL query in a text to create an executable object.

Also, LoanParcel is a table not a database in your example.

from sqlalchemy import create_engine, text

engine = create_engine("mysql+pymysql://mariadb:mariadb@localhost:9051/mariadb")

def user_detail(req, id):
    conn = engine.connect()
    QLoanParcel = text("SELECT * FROM LoanParcel")
    dfParcel = pd.read_sql(QLoanParcel, conn)
    conn.close()
    df = dfParcel.drop(["id", "date_add", "start_date"], axis = 1)
    return render(req,'pages/user_detail.html')
like image 84
ljmc Avatar answered Sep 10 '26 01:09

ljmc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!