Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3 SQLite IntegrityError_Python_Sqlite_Python 3.x - Fatal编程技术网

Python3 SQLite IntegrityError

Python3 SQLite IntegrityError,python,sqlite,python-3.x,Python,Sqlite,Python 3.x,我试图调试代码返回错误的原因。我有一个SQLite数据库,我正试图将记录添加到一个特定的表中。我的代码在Python2.7中运行得非常好,但在Python3.5中我得到了IntegrityError new_rec = [1, 12.0, -12.0, None, None, b'fakesource', None, None] self.conn.execute("INSERT INTO {} VALUES({})".format('sources', ','.join('?' * len(c

我试图调试代码返回错误的原因。我有一个SQLite数据库,我正试图将记录添加到一个特定的表中。我的代码在Python2.7中运行得非常好,但在Python3.5中我得到了
IntegrityError

new_rec = [1, 12.0, -12.0, None, None, b'fakesource', None, None]
self.conn.execute("INSERT INTO {} VALUES({})".format('sources', ','.join('?' * len(columns))), tuple(new_rec))
columns
是我的表中的列名列表。它的长度与
new\u rec
相同

这将返回:

sqlite3.IntegrityError: datatype mismatch
以下是表格模式供参考:

CREATE TABLE sources (id INTEGER PRIMARY KEY, 
ra REAL, 
dec REAL, 
designation TEXT, 
publication_id INTEGER, 
shortname TEXT, 
names TEXT, 
comments TEXT)
new\u rec
更改为如下内容:
new\u rec=[1,12.0,None,None,None,None,None]
仍然会导致
整数错误。有什么想法吗

更新日期:2016年8月16日 我已经检查了
new\u rec
的类型,相信我发现了问题:

[<class 'numpy.int64'>, <class 'numpy.float64'>, <class 'numpy.float64'>, <class 'NoneType'>, <class 'NoneType'>, <class 'numpy.bytes_'>, <class 'NoneType'>, <class 'NoneType'>]
[,,,]

看起来sqlite3对numpy.int64不起作用:

完整性错误意味着表中已存在具有相同主键的条目。当表已经有键时,是否尝试插入键为1的行?这可能不是Python的问题……可能只是您最初在Python 2.7中插入了行。不,表是空的,将id更改为其他内容仍然会导致错误。在我看来,这就像我的代码中的其他东西,或者我的sqlite3版本,正在崩溃,因为不应该出现数据类型不匹配错误。