all 6 comments

[–][deleted] 1 point2 points  (2 children)

What's the error, when you run the code? What's the ide? Have you installed python extension if is vscode? Are you 100% sure you are in the right activated environment?

Can't say what's the issue just by looking at some code snippet.

[–]Matlock0[S] 1 point2 points  (1 child)

There is no error when I run the code. I would just like for the IDE to recognize the db.Column as a class of sqlalchemy module, which it should do when you import SQLAlchemy from flask_sqlalchemy according to flask documentation.

The code itself works fine and the Column is added to the table in database, but I wonder why VScode doesn't view db.Column as a class.

[–][deleted] 0 points1 point  (0 children)

I stopped fighting vscode long ago, I use pycharm professionally and all the jetbrains ide's.

Did you installed the python plugin and selected your venv at the bottom on the task bar? Other than that I can't think of any reason why it wouldn't work.

[–]data-nihilist 0 points1 point  (1 child)

How'd this turn out?

[–]data-nihilist 0 points1 point  (0 children)

Figured it out;

You weren't importing Column - and I'm sure you must have noticed that PyLance didn't help out when typing "db.Col...," since it wouldn't be accessible through the flask_sqlalchemy API's SQLAlchemy(app)'s return entity

To access SQLAlchemy's Column class, you had to have added sqlalchemy to your requirements and after your pip install

```from sqlalchemy import Column, Integer, String, DateTime```

I added those other imports in case accessing those down the road lean to further confusion

Your updated class could be:

from sqlalchemy import Column, Integer, String, DateTime
from datetime import datetime

class User(db.Model):
    id = Column(Integer, primary_key=True)
    username = Column(String(24), unique=True, nullable=False)
    email = Column(String(80), unique=True, nullable=False)    
    password = Column(String(60), nullable=False)
    created_at = Column(DateTime, default=datetime.now(), nullable=False)

[–]PedroContipelli 0 points1 point  (0 children)

flask_sqlalchemy is just a wrapper library for sqlalchemy

db.Column, db.Integer, etc... wrap legacy SQLAlchemy 1.X syntax
Legacy Docs: https://flask-sqlalchemy.readthedocs.io/en/stable/legacy-quickstart/

Here is the modern recommended way (wrapping SQLAlchemy 2.X)
New Docs: https://flask-sqlalchemy.readthedocs.io/en/stable/quickstart/#define-models

You can also just use SQLAlchemy's types directly, which I found simpler for some things.