解决 "OperationalError: (sqlite3.OperationalError) no such table: ..."问题
参考:flask/sqlalchemy - OperationalError: (sqlite3.OperationalError) no such table
在用Flask写一个简单的py文件,做一个表单时,发现在login界面登陆的时候,出现:
OperationalError: (sqlite3.OperationalError) no such table: ...
错误,这个问题肯定是与数据库有关的;于是review了一下代码,关于数据库ORM的声明类Switches如下:
class Switches(db.Model):
__tablename__ = 'Switches'
sid = db.Column(db.Integer, primary_key=True)
sname = db.Column(db.String, unique=True, index=True)
#sprice = db.Column(db.Integer)
def __repr__(self):
print('<Switch_id %d>' % id)
两列Column,一个主key叫做sid,外加一个属性sname,没有问题;也排除了app.config的问题,那么就是视图函数中的问题了。
但是看上去也没有问题:
@app.route('/', methods=['GET', 'POST'])
def index():
form = NameForm()
if form.validate_on_submit():
sw = Switches.query.filter_by(sname=form.name.data).first() # filter the DB
if sw is None:
sw = sw(sname=form.name.data)
db.session.add(sw)
session['known'] = False
else:
session['known'] = True
session['name'] = form.name.data
return redirect(url_for('myindex'))
return render_template('myindex.html', form=form, name=session.get('name'),
known=session.get('known', False))
逻辑语句if内是对表单的具体操作,在Swicthes数据库中找名字为输入数据的tuple,然后进行相关操作。
于是乎求助搜索引擎,在参考的那篇文章中回答者给出了这样的解释:
You're supposed to initialize/create the tables first. Please read the Creating the Database article in the official Flask documentation:
Such systems need a schema that tells them how to store that information. So before starting the server for the first time it’s important to create that schema.
Here's Flask's example of using a schema SQL script to create the database, tables, etc:
sqlite3 /tmp/flaskr.db < schema.sql
The recommended way is to use db.create_all() within your app. For example, see: https://github.com/hypatia-software-org/staticfuzz/blob/master/staticfuzz.py#L391
大意是数据库没有创建这张表,一个推荐的解决方法是加入db.create_all()语句来创建表。
2017.3.30
解决 "OperationalError: (sqlite3.OperationalError) no such table: ..."问题的更多相关文章
- sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) Cannot add a NOT NULL column with default value NULL [SQL: u'ALTER TABLE address_scopes ADD COLUMN ip_version INTEGER NOT NULL']
root@hett-virtual-machine:~# su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neu ...
- flask/sqlalchemy - OperationalError: (sqlite3.OperationalError) no such table
狗书第五章 记得要先创建表 执行 db.create_all()语句来创建表 https://segmentfault.com/q/1010000005794140
- (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.id AS users_id, users.email AS users_email, users.username AS users_username, users.role_id AS users_role_id, users.password_hash A
在注册新用户的时候报错: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.id AS users_id, use ...
- 转!sqlite3.OperationalError) no such table- users [SQL- 'SELECT users.id AS users_id, users.email AS u
在注册新用户的时候报错: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.id AS users_id, use ...
- Airflow安装错误:sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError)
1 完整的异常信息: raise errorclass, errorvalue sqlalchemy.exc.OperationalError: (_mysql_exceptions.Operatio ...
- sqlite3.OperationalError: no such table: account_user
你可能是在项目中安装了多个app, 首先删除相关app的migration文件中的子文件 执行建表的时候使用: python manage.py makemigrations appname pyth ...
- 解决 pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 61] Conne
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 61] ...
- magento -- 解决magento错误:ERROR: Base table or view already exists: 1050 Table ... already exists
相信有更新magento或者,备份转移magento站点的时候可能会碰到类似这样的错误提示: Base table or view already exists: 1050 Table ... alr ...
- 【MySQL】解决You can't specify target table 'user_cut_record_0413' for update in FROM clause
问题 You can't specify target table 'user_cut_record_0413' for update in FROM clause 原因 待更新/删除的数据集与查询的 ...
随机推荐
- Windows Phone WebClient的使用
webClient对象可用来下载XML文件,程序集等这些数据,其可以实现按需下载,所以还是有必要了解的.其主要包含几个事件: ...
- (转)梯度下降法及其Python实现
梯度下降法(gradient descent),又名最速下降法(steepest descent)是求解无约束最优化问题最常用的方法,它是一种迭代方法,每一步主要的操作是求解目标函数的梯度向量,将当前 ...
- thymeleaf 学习笔记-基础篇(中文教程)
(一)Thymeleaf 是个什么? 简单说, Thymeleaf 是一个跟 Velocity.FreeMarker 类似的模板引擎,它可以完全替代 JSP .相较与其他的模板引擎,它有如下 ...
- 170804、使用Joda-Time优雅的处理日期时间
简介 在Java中处理日期和时间是很常见的需求,基础的工具类就是我们熟悉的Date和Calendar,然而这些工具类的api使用并不是很方便和强大,于是就诞生了Joda-Time这个专门处理日期时间的 ...
- OA之为用户设置角色和为用户设置权限
1.为用户设置角色 { Layout = null; } @using OA.Model <!DOCTYPE html> <html> <head> <met ...
- Git之删除仓库
Github删除已有仓库步骤 在仓库页面点击设置 在新打开网页删除 输入仓库名点击删除即可
- Cisco配置发送日志到日志服务器
Cisco配置发送日志到日志服务器logging 172.16.6.22logging onlogging trap 7 //指定日志消息的级别 (0:紧急(Emergencies) 1:告警(Al ...
- pta 习题集5-17 家谱处理
人类学研究对于家族很感兴趣,于是研究人员搜集了一些家族的家谱进行研究.实验中,使用计算机处理家谱.为了实现这个目的,研究人员将家谱转换为文本文件.下面为家谱文本文件的实例: John Robert F ...
- 洛谷P2444 病毒【AC自动机】
题目描述 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已经找出了所有的病毒代码段,试问,是否 ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 0: illegal multibyte sequence
使用Python写文件的时候,或者将网络数据流写入到本地文件的时候,大部分情况下会遇到:UnicodeEncodeError: 'gbk' codec can't encode character ' ...