2

I set up a blog website, when I did try to connect my website to database so I got unresolved attribute reference 'Column' for class 'SQLALchemy' error. Although server is running but in the case of database connection I'm getting error.

my pycharm interpreter path set properly. I import all the module. Even I checked twice times.

I know this question is already asked but I'd get any help.

My code:

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)
Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
dalal
  • 19
  • 1
  • 6

0 Answers0