Python2.7 Mysql connector Error

finndai 发布于 2017/02/15 19:49
阅读 206
收藏 0
/usr/bin/python2.7 /home/finnidai/finndai-python-webapp/www/test_db.py
WARNING:root:NOTE:change primary key to non-updatable
WARNING:root:NOTE:change primary key to non-updatable
WARNING:root:NOTE:change primary key to non-updatable
Traceback (most recent call last):
  File "/home/finnidai/finndai-python-webapp/www/test_db.py", line 12, in <module>
    u.insert()
  File "/home/finnidai/finndai-python-webapp/www/transwarp/orm.py", line 242, in insert
    db.insert('%s'% self.__table__,**params)
  File "/home/finnidai/finndai-python-webapp/www/transwarp/db.py", line 269, in insert
    return _update(sql,*args)
  File "/home/finnidai/finndai-python-webapp/www/transwarp/db.py", line 133, in _wrapper
    return func(*args,**kw)
  File "/home/finnidai/finndai-python-webapp/www/transwarp/db.py", line 241, in _update
    cursor.execute(sql,args)
  File "/usr/lib/python2.7/dist-packages/mysql/connector/cursor.py", line 552, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 490, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 395, in _handle_result
    raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1146 (42S02): Table 'test.users' doesn't exist

一直提示错误表没有创建,但是找不到错误在哪里,什么捉急,恳请各位指教一下。

这是ORM模块的insert

  def insert(self):
        self.pre_insert and self.pre_insert()
        params = {}
        for k,v in self.__mappings__.iteritems():
            if v.insertable:
                if not hasattr(self,k):
                    setattr(self,k,v.default)
                params[v.name] = getattr(self,k)

        db.insert('%s'% self.__table__,**params)
        return self

这是db模块的insert语句

@with_connection
def _update(sql,*args):
    global _db_ctx
    cursor = None
    sql = sql.replace('?','%s')
    logging.info('SQL:%s,ARGS:%s' %(sql,args))
    try:
        cursor = _db_ctx.connection.cursor()
        cursor.execute(sql,args)
        r = cursor.rowcount
        if _db_ctx.transactions == 0:
            logging.info('auto commit')
            _db_ctx.connection.commit()
        return r
    finally:
        if cursor:
            cursor.close()


def insert(table,**kw):
   
    cols,args = zip(*kw.iteritems())
    sql = 'insert into `%s`(%s) values (%s)' %(table,','.join(['`%s`' % col for col in cols]),','.join(['?'for i in range(len(cols))]))
    return _update(sql,*args)

 

加载中
返回顶部
顶部