flask - 烧瓶中的 sqlalchemy.exc.OperationalError
问题描述
您好,我是一名新程序员,我刚开始用烧瓶制作网站,在我最近的项目中,我遇到了数据库问题(错误名称是标题;))这是我的代码(我正在制作一个迷你 youtube)
@app.route("/create_acc", methods=["POST", "GET"])
def create_acc():
if request.method == "POST":
name = request.form["nm"]
check = ChannelDB.query.filter_by(name=name).first()
if not check:
email = request.form["em"]
psw = request.form["ps"]
channel = ChannelDB(name, email, psw, 0, 0)
db.session.add(channel)
db.session.commit()
return redirect(url_for("user"))
else:
abort(409, message="Video alredy exists")
这是产生错误的地方。
class ChannelDB(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
email = db.Column(db.String(100), nullable=False)
password = db.Column(db.String(100), nullable=False)
subs = db.Column(db.Integer, nullable=False)
num_of_videos = db.Column(db.Integer, nullable=False)
这是我的数据库。
{% extends "base.html" %}
{% block title %}Login Page{% endblock %}
{% block content %}
<form action="/create_acc", method="post">
<p>Name: </p>
<p><input type="text" name="nm"></p>
<p>Email: </p>
<p><input type="text" name="em"></p>
<p>Password: </p>
<p><input type="text" name="ps"></p>
<p>Press this button when you fill the spots above</p>
<p><input type="submit" value="submit"></p>
</form>
{% end block %}
这是我的登录名。.html 文件
解决方案
错误的完整摘录会更具决定性。不过,如果您能够使用终端在表中添加记录,请尝试。
from app import *
channel = ChannelDB("Sample name", "sample email", "pass", 0, 0)
db.session.add(channel)
db.commit()
如果上述命令未执行,请删除表并重新创建它们。
from app import db
db.drop_all()
db.create_all()
如果没有,请尝试重新创建表
推荐阅读
- ios - ITMS-90892:Apple App Store 中缺少推荐的图标错误
- android - Gradle 签署 Android 库出版物:无法执行签名任务,因为它没有配置的签名者
- javascript - 在 vueJS 中调用 EventBusses 时,其中一个根本不起作用
- javascript - 根据状态变量反应变化输入元素
- mysql - 最佳解释计划
- node.js - Node.js - 导出时功能不起作用
- apache-kafka - 监控 Kafka 是否启动?
- scheme - 计算机程序的结构和解释 Ex2_74
- google-apps-script - 谷歌表格脚本下载
- java - 如何从 Angular 中的 Java 服务中检索数据(键/值)?