当我尝试将网站连接到数据库时,我建立了一个博客网站,因此出现unresolved attribute reference 'Column' for class 'SQLALchemy'
错误。虽然服务器正在运行,但是在数据库连接的情况下
我的pycharm解释器路径设置正确。 我导入所有模块。甚至我检查了两次。
我的代码:
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__, template_folder='template', static_folder='static')
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@server/db'
db = SQLAlchemy(app)
class Contact(db.Model):
# This 'Column' and 'Integer' error?
Name = db.Column(db.Integer, primary_key=True)
Email = db.Column(db.String(30), nullable=False)
Phone = db.Column(db.String(12), nullable=False)
Message = db.Column(db.String(120), nullable=False)
@app.route('/')
def main():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact', methods=['GET', 'POST'])
def contact():
if request.method== 'POST':
name=request.form.get('name')
email=request.form.get('email')
phone=request.form.get('phone')
msg=request.form.get('msg')
add = Contact(Name=name, Email=email, Phone=phone, Message=msg)
db.session.add(add)
db.commit()
return render_template('contact.html')
@app.route('/post')
def post():
return render_template('post.html')
app.run(debug=True)