英文:
Not an executable object: 'SELECT * FROM LoanParcel'
问题
以下是翻译好的部分:
"我想通过将数据库创建为数据帧来使用它,并且我已经使用了SQLAlchemy来导入create_engine
,但我遇到了'不可执行对象:'SELECT * FROM LoanParcel''的问题,其中'LoanParcel'是我要创建为数据帧的数据库名称,我应该如何修复它?
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')
希望这能帮助你解决问题。
英文:
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')
答案1
得分: 8
SQLAlchemy 2引入了重大变更,您需要将SQL查询包装在[`text`][1]中以创建可执行对象。
此外,在您的示例中,`LoanParcel`是一个表而不是数据库。
英文:
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')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论