I am using pycharm 5.0 and python3.5. And I load all liarbry using the built-in pycharm function (project-project-project interpreter - "+"). Other libraries look good, but some problems happen with the -SQLAlchemy flask.
i successfully imports SQLAlchemy flag. However, pycharm reminds me that there is an "unresolved reference to the Column attribute in class'SQLAlchemy." "unresolved attribute reference link" in the "SQLAlchemy" class, etc.
I tried several methods, but they did not work. For example: 1.restart 2.remove and redownload 3.refresh cache.which a mention in PyCharm shows unresolved error links for valid code
code:
from flask import Flask, redirect, render_template, session, url_for, flash
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from flask_wtf import Form
from wtforms import StringField, SubmitField
import os
from wtforms.validators import data_required
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hard to guess string'
app.config['SQLALCHEMY_DATABASE_URI'] =\
'sqlite:///' + os.path.join(basedir, 'data.sqlite')
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
bootstrap = Bootstrap(app)
db = SQLAlchemy(app)
class Role(db.Model):
__tablename__ = 'roles'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), unique=True)
users = db.relationship('User', backref='role', lazy='dynamic')
def __repr__(self):
return '<Role %r>' % self.name
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), unique=True, index=True)
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
def __repr__(self):
return '<User %r>' % self.username
?