- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 sqlalchemy 的 Flask 应用程序。运行manage db init
、manage db migrate
和manage db Upgrade
工作得很好。所以在db2上创建表没有任何问题。当我尝试插入时,出现各种错误。
Traceback (most recent call last):
File "*path*/lib/python3.6/site-packages/ibm_db_dbi.py", line 1258, in _execute_helper
return_value = ibm_db.execute(self.stmt_handler, parameters)
Exception: Binding Error:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/ibm_db_sa/ibm_db.py", line 107, in do_execute
cursor.execute(statement, parameters)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/ibm_db_dbi.py", line 1356, in execute
self._execute_helper(parameters)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/ibm_db_dbi.py", line 1268, in _execute_helper
raise self.messages[len(self.messages) - 1]
ibm_db_dbi.DatabaseError: ibm_db_dbi::DatabaseError: Binding Error:
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/flask_restplus/api.py", line 319, in wrapper
resp = resource(*args, **kwargs)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/flask/views.py", line 88, in view
return self.dispatch_request(*args, **kwargs)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/flask_restplus/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api/app/api.py", line 37, in get
snp.sensor_info()
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api/app/network.py", line 123, in sensor_info
db_session.commit()
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", line 153, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 943, in commit
self.transaction.commit()
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 467, in commit
self._prepare_impl()
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 447, in _prepare_impl
self.session.flush()
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2254, in flush
self._flush(objects)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2380, in _flush
transaction.rollback(_capture_exception=True)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 187, in reraise
raise value
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2344, in _flush
flush_context.execute()
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", line 391, in execute
rec.execute(self)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", line 556, in execute
uow
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/persistence.py", line 181, in save_obj
mapper, table, insert)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/orm/persistence.py", line 830, in _emit_insert_statements
execute(statement, multiparams)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 948, in execute
return meth(self, multiparams, params)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 269, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1060, in _execute_clauseelement
compiled_sql, distilled_params
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context
context)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
exc_info
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/ibm_db_sa/ibm_db.py", line 107, in do_execute
cursor.execute(statement, parameters)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/ibm_db_dbi.py", line 1356, in execute
self._execute_helper(parameters)
File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/ibm_db_dbi.py", line 1268, in _execute_helper
raise self.messages[len(self.messages) - 1]
sqlalchemy.exc.DatabaseError: (ibm_db_dbi.DatabaseError) ibm_db_dbi::DatabaseError: Binding Error: [SQL: 'INSERT INTO "schema"."table" (sensor_id, code, lat, lon, x, y) VALUES (?, ?, ?, ?, ?, ?)'] [parameters: (2855, 30, 59.291658, 18.077241, 411.59730406100783, 769.5522643844229)] (Background on this error at: http://sqlalche.me/e/4xp6)
模型看起来像:
class Sensor(Base):
__tablename__ = 'table'
__table_args__ = {'schema':'schema'}
sensor_id = db.Column(db.Integer, primary_key=True)
code = db.Column(db.Integer, unique=True, nullable=False)
lat = db.Column(db.Float, unique=True, nullable=False)
lon = db.Column(db.Float, unique=True, nullable=False)
x = db.Column(db.Float, unique=True, nullable=False)
y = db.Column(db.Float, unique=True, nullable=False)
def __repr__(self):
return '<Sensor %r, x=%r, y=%r>' % self.code % self.x % self.y
插入代码如下所示:
from .models import Sensor
from .database import db_session
ins = Sensor(sensor_id = sensor_coords['sensor_code'][0],
code = sensor_coords['sensor'][0],
lat = sensor_coords['lat'][0],
lon = sensor_coords['long'][0],
x = sensor_coords['x'][0],
y = sensor_coords['y'][0])
db_session.add(ins)
db_session.commit()
查看错误消息,这就是它尝试绑定(bind)sql语句的方式:[SQL: 'INSERT INTO "schema"."table"(sensor_id, code, lat, lon, x, y) VALUES (?, ?, ?, ?, ?, ?)'] [参数:(2855 , 30, 59.291658, 18.077241, 411.59730406100783, 769.5522643844229)]
哪个看起来正确? (模式和表名称被替换)。
我的database.py
看起来像:
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import ibm_db_sa
from app.api import app
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'], convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
def init_db():
Base.metadata.create_all(bind=engine)
我不知道出了什么问题。插入格式看起来正确吗?
感谢我能得到的所有帮助。谢谢!
最佳答案
开始工作了!
必须将插入代码中的类型转换为:
ins = Sensor(sensor_id = int(sensor_coords['sensor_code'][0]),
code = int(sensor_coords['sensor'][0]),
lat = float(sensor_coords['lat'][0]),
lon = float(sensor_coords['long'][0]),
x = float(sensor_coords['x'][0]),
y = float(sensor_coords['y'][0]))
没有意识到 numpy 使用自己的 int 和 float 类型...
关于python - 使用 Flask 和 sqlalchemy 插入到 Db2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51098540/
我当前正在存储给定产品的上传图像,如下所示: class Product(db.Model): images= db.ListProperty(db.Blob) # More prop
每次对架构或新迁移文件进行更改时,我都会运行以下命令: rake db:drop db:create db:migrate db:seed 是否有预先构建的等效方法来执行此操作? 我从我读到的内容中想
在 android 中使用房间作为数据库。当我试图在 sqlviewer 中查看数据时,在数据库文件中找不到表Myapp.db 文件为空。数据/data/packageName/databases/M
我搜索并尝试了很多次,但没有找到我的答案。我有一些用小 cucumber (在 Rails 项目中)编写的项目的功能文件。所有步骤都已定义,如果我单独启动它们,功能本身运行得很好。我可以将所有场景与我
您必须承认,对于 Rails 和数据库的新手来说,rubyonrails.org 上的官方解释使所有这四个任务听起来完全一样。引用: rake db:test:clone Recreate the
当我尝试运行时: heroku run rake db:drop db:create db:migrate 我得到错误: Running rake db:drop attached to termin
rake db:migrate 和 rake db:reset 之间的区别对我来说非常清楚。我不明白的是 rake db:schema:load 与前两者有何不同。 只是为了确保我在同一页面上: ra
我们都知道,我们可以使用 Azure 函数(使用 out 参数或使用 return)在 cosmos DB 中一次保存一个文档,例如: object outputDocument = new { i
我有一个包含 60 多个表的 mysql 数据库。这是在我将 joomla 版本 2.5.3 从本地灯移植到网络服务器时构建的。 我运行 mysql-db: 移植后我发现我无法登录 amdin 区域。
我想轻松地将现有数据库迁移到 Azure 托管。在我的项目中,我使用 Entity Framework DB First。有什么经验教训或例子可以说明如何做到这一点吗? 最佳答案 您本地使用什么数据库
所以,我一直在使用 MagicalRecord 开发 iPad 应用程序,最近在转移到自动迁移商店后我遇到了一些问题。我需要将我的 .db 文件从一个设备同步到另一个设备,所以我需要所有数据都在 .d
自从我在 Heroku 上部署并希望与生产相匹配后,我最近切换到 postgres 来开发一个 Rails 应用程序。当我将数据库名称设置为“postgres”时,我的应用程序安装了 Postgres
我使用 oledb 提供程序(SQLOLEDB 和 SQL Native OLEDB 提供程序)创建了一个示例应用程序。 案例 1:提供者 = SQLOLEDB hr = ::CoInitialize
我正在为 NodeJs 使用 mongodb 驱动程序,其中有 3 个方法: 1) db.collection.insert 2) 数据库.collection.insertOne 3) db.col
我是 datomic 的新手,我仍在努力弄清楚系统是如何构建的。特别是,我不明白 :db.part/db 扮演什么角色,因为每次安装架构时似乎都需要它。有人可以解释一下这一切意味着什么吗? (需要 '
Berkeley DB 是否有空间索引,例如 R-tree? 最佳答案 有人问the same question on the Oracle forum .还没有甲骨文回答。但答案是否定的,它没有任何
请解释一下这是什么意思 $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); 它给了我一个错误 "E
berkeley-db-je 的最新版本是什么? 来自 oracle , 为 7.5。 但来自maven存储库,它是 18.3.12。 有没有人知道更多的细节? 最佳答案 Berkeley DB Ja
我不明白查询构建器的替换和更新之间的区别。尤其是替换文档... This method executes a REPLACE statement, which is basically the SQL
看起来 BerkeleyDB 被 Oracle 收购了,它没有在其网站上发布源代码? 最佳答案 Sleepycat 于 2006 年被 Oracle 收购。该产品继续在原始开源许可下可用,并继续得到增
我是一名优秀的程序员,十分优秀!