I am creating my first backend with python and flask, and i have run into this error: "Instance of 'SQLAlchemy' has no 'Column' member". I tried to solve the issue by following similar questions here from stackoverflow, but it doesn't work. Solutions i have tried:
installed flask-sqlalchemy,
installed flask,
added
"python.linting.pylintArgs": [
"--load-plugins",
"pylint-flask-sqlalchemy",
"pylint-flask"
]
to my settings.json file,
basicly i followed this thread: Instance of 'SQLAlchemy' has no 'Column' member (no-member) but without succes. What i am trying to achieve is actually just to copy-paste this tuturial: https://www.codementor.io/@dongido/how-to-build-restful-apis-with-python-and-flask-12qto530jd
And i have gotten succesfully through until step number 5, which is creating the model.
Does anyone have further information on how to solve this issue?
UPDATE: When i run the program i get:
Traceback (most recent call last):
File "run.py", line 17, in <module>
app = create_app("config")
File "run.py", line 10, in create_app
from Model import db
File "C:\Users\Madsen\AndroidStudioProjects\JustDoItApp\Backend\Model.py", line 3, in <module>
from flask_marshmallow import Marshmallow
File "C:\Users\Madsen\AndroidStudioProjects\JustDoItApp\Backend\env\lib\site-packages\flask_marshmallow\__init__.py", line 24, in <module> import flask_sqlalchemy # flake8: noqa
File "C:\Users\Madsen\AndroidStudioProjects\JustDoItApp\Backend\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 39, in <module>
_timer = time.clock
AttributeError: module 'time' has no attribute 'clock'
The program isn't ready for running though. But in the tuturial i am following, this shouldn't be causing an error. Can it be that the database i am connecting to is the problem? I am connecting to my localhost postgresql like this from confi.py:
SQLALCHEMY_DATABASE_URI = os.environ.get("postgresql://postgres:password@localhost/BilletApp")
and i have filled the password field with my localhost password. This database doesn't have table called 'comments', like what i am trying to create here with this code:
class Comment(db.Model):
__tablename__ = 'comments'
id = db.Column(db.Integer, primary_key=True)
comment = db.Column(db.String(250), nullable=False)
creation_date = db.Column(db.TIMESTAMP, server_default=db.func.current_timestamp(), nullable=False)
category_id = db.Column(db.Integer, db.ForeignKey('categories.id', ondelete='CASCADE'), nullable=False)
category = db.relationship('Category', backref=db.backref('comments', lazy='dynamic' ))
def __init__(self, comment, category_id):
self.comment = comment
self.category_id = category_id.
Could this be the issue?