我正在使用sqlalchemy
ORM
我在four tables
中有database
['eventtable', 'locationTable', 'activityTable', 'usernameTable']
当我使用sqlalchemy.engine.reflection.Inspector.get_columns
检查列名时我得到activityTable
的列名列表,我得到了所有名称
[{'name':'campaignid','type':INTEGER(),'nullable':True,'default':None,'autoincrement':'auto','primary_key':0},{'名称”:“用户名”,“类型”:TEXT(),“可空”:真,“默认值”:无,“自动增量”:“自动”,“主键”:0},{“名称”:“广告系列名称” ,'type':TEXT(),'nullable':True,'default':无,'autoincrement':'auto','primary_key':0},{'name':'device','type':TEXT (),'nullable':True,'default':无,'autoincrement':'auto','primary_key':0},{'name':'mediaid','type':INTEGER(),'nullable' :True,'默认':无,'autoincrement':'auto','primary_key':0},{'name':'fromdate','type':TEXT(),'nullable':True,'default' :无,'autoincrement':'auto','primary_key':0},{'name':'todate','type':TEXT(),'nullable':True,'default':无,'autoincrement' :'auto','primary_key':0},{'name':'popupid','type':INTEGER(),'nullable':True,'default':无,'autoincrement':'auto',' primary_key':0},{'name':'gender','type':TEXT(),'nullable':True,'defau lt':无,'autoincrement':'auto','primary_key':0},{'name':'isactive','type':TEXT(),'nullable':True,'default':None,' autoincrement':'auto','primary_key':0},{'name':“'isdeleted'”,'type':TEXT(),'nullable':True,'default':无,'autoincrement':'自动”,“ primary_key”:0}]
但是当我尝试插入值
def loadDatabaseExtractTable(dbFileLoaction,tableName):
# Load the exisiting db onto engine
engine = create_engine(dbFileLoaction,connect_args={'check_same_thread': False})
# call MetaData
metadata = MetaData()
# Extract a specific table from db
extractedTable = Table(tableName, metadata, autoload=True, autoload_with=engine)
# connect to the engine
connection = engine.connect()
# Session to perform CRUD operations
Session = sessionmaker(bind=engine)
session = Session()
return session,extractedTable,engine
activityTableName = 'activityTable'
activityTableSession,activityTable,activityTableEngine = loadDatabaseExtractTable(c1_database_file,activityTableName)
current_campaign_id = 0
campaignName= 'ahjs'
deviceName= 'assd'
selected_media_id = 1
fromDate = 'jkhdsf'
toDate = 'lksdf'
selected_popup_id = 1
gender ='jkh'
campaign_active = True
activity_details = {'campaignid':current_campaign_id+1,'username':'test1','campaignname':campaignName\
,'device':deviceName,'mediaid':selected_media_id,'fromdate':fromDate,'todate':toDate\
,'popupid':selected_popup_id,'gender':gender,'isactive':str(campaign_active),'isdeleted':'False'}
i = insert(activityTable).values(activity_details)
activityTableSession.execute(i)
activityTableSession.commit()
我收到此错误
回溯(最近通话最近一次):
文件“ server_v0.1.py”,第112行,在 activityTableSession.execute(i)
在执行中的文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/orm/session.py”中,行1269 子句,参数或{}
在执行中的文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/engine/base.py”中,第988行 返回meth(self,multiparams,params)
文件_execute_on_connection中的第287行“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/elements.py” 返回连接。_execute_clauseelement(自身,多参数,参数)
文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/engine/base.py”,行1098,在_execute_clauseelement中 其他没有,
文件“”,第1行,在 编译文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/elements.py”,行462 返回self._compiler(方言,bind = bind,** kw)
_compiler中的文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/elements.py”,行468 返回方言.statement_compiler(方言,自我,** kw)
文件 init 已编译。初始化(自我,方言,陈述,**变态)
文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py”,第319行, init self.string = self.process(self.statement,** compile_kwargs)
文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py”,第350行,正在处理中 返回obj._compiler_dispatch(self,** kwargs)
_compiler_dispatch中的第91行,文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py” 返回meth(self,** kw)
文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py”,第2387行,位于visit_insert中 自我,insert_stmt,crud.ISINSERT,** kw
文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/crud.py”,第62行,位于_setup_crud_params中 返回_get_crud_params(编译器,stmt,** kw)
文件“ /home/ffffff/.virtualenvs/flask-app/lib/python3.6/site-packages/sqlalchemy/sql/crud.py”,行177,在_get_crud_params中 %(“,” .join(“%s”%c对于检查中的c)) sqlalchemy.exc.CompileError:未使用的列名称:popupid,mediaid,todate,campaignid,isactive,isdeleted,campaignname,fromdate
很难解决此问题?
列存在,但仍会获取sqlalchemy.exc.CompileError: Unconsumed column names
请指导,我在sqlalchemy github上也提出了同样的问题