繁体   English   中英

AttributeError: 模块 'sqlalchemy' 没有属性 'NullType'

[英]AttributeError: module 'sqlalchemy' has no attribute 'NullType'

我正在尝试使用 MySQLWorkBench 配置 Flask SQLAlchemy,以下命令效果很好。
烧瓶数据库迁移-m'配置'
但是当我尝试执行flask db upgrade时出现以下错误。

AttributeError: module 'sqlalchemy' has no attribute 'NullType'

什么是解决方案?

应用程序.py:

from flask import Flask , render_template ,redirect, url_for, request
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from datetime import datetime

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:password!@localhost/blog'

# initialize
db = SQLAlchemy(app)
migrate = Migrate(app, db)

# To Db
class PostTable(db.Model):
    sno = db.Column(db.Integer, primary_key=True, unique=True, nullable=False)
    date = db.Column(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), nullable=False)
    name = db.Column(db.String(120), unique=False, nullable=False)
    emailid = db.Column(db.String(50), unique=False, nullable=False)
    phone = db.Column(db.String(15), unique=False, nullable=False)
    message = db.Column(db.String(120), unique=False, nullable=False)

@app.route("/")
def home():
    return render_template('index.html')

@app.route("/homeclick")
def homeclick():
    return render_template('index.html')

@app.route("/about")
def about():
    return render_template('about.html')

@app.route("/post")
def post():
    return render_template('post.html')

@app.route("/contact" , methods=['POST', 'GET'])
def contact():
    if request.method == 'POST' :
        # add entry to the database

        name = request.form.get('name')
        emailid = request.form.get('email')
        phone = request.form.get('phone_number')
        message = request.form.get('message')

        entry_to_db = PostTable(name=name, emailid=emailid , phone=phone,message=message)
        db.session.add(entry_to_db)
        db.session.commit()
        return render_template('contact.html')

       if __name__ == '__main__':
       app.run(debug=True, port=4013 , threaded=True)

首先,这是错误的缩进

if __name__ == '__main__':
       app.run(debug=True, port=4013 , threaded=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM