Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.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
Python Sqlite3将数据存储为文本而不是整数_Python_Sqlite - Fatal编程技术网

Python Sqlite3将数据存储为文本而不是整数

Python Sqlite3将数据存储为文本而不是整数,python,sqlite,Python,Sqlite,我在Sqlite3中创建了一个表,如下所示: def create_table(self): """create a database table if it does not exist already""" self.cur.execute('''CREATE TABLE IF NOT EXISTS jobs(title text, \ job_id integer

我在Sqlite3中创建了一个表,如下所示:

def create_table(self):
    """create a database table if it does not exist already"""
    self.cur.execute('''CREATE TABLE IF NOT EXISTS jobs(title text, \
                                                        job_id integer PRIMARY KEY, 
                                                        age integer)''')
“年龄”定义为整数。但当我在SQLite的DB Browser中执行此查询时:

Pragma table_info(jobs);
我得到的回答是:

Query executed successfully: Pragma table_info(jobs); (took 1ms)

cid name type  pk
2   age  text  0 //rows title and job_id have been ignored as they are as expected
“年龄”是数据类型文本

可能的原因是:

  • 当插入一行数据时,插入到年龄列中的数据是文本,但如果是这种情况,则会出现另一个问题,sqlite3在插入数据之前是否检查数据类型

如果您删除表格并重新创建它,问题是否仍然存在?因为只有当它不存在时才创建它,所以它可能是旧版本的工件

结果与我预期的一样:

0|title|text|0||0
1|job_id|integer|0||1
2|age|integer|0||0

真奇怪!!我放弃了这个表,重新执行了我的程序,它按预期工作。有趣的是:在创建新表之前,我把旧表扔掉了,然后我问题中的这个问题就发生了。你以前遇到过类似的问题吗?不是个人的问题,但是可能旧的drop没有成功或者类似的事情,或者你打开了一个不同的DB。