Instance of 'SQLAlchemy' has no 'Column' member (no-member)

前端 未结 6 2146
清酒与你
清酒与你 2020-12-13 02:25

I\'m currently trying to implement steam login into website. But I\'m unable to get pass this error within the code. I\'ve created the database object but it keeps showing t

相关标签:
6条回答
  • 2020-12-13 02:53

    Summary of working and non-working configurations

    It seems that this can be configured so many ways incorrectly, that I decided to write the different options down. I am assuming VS Code, but for command line or other editor, arguments and their order is the same. These were tested using the latest versions of all the packages (list in the bottom of this post)

    Working versions

    # What you'll need is pylint_flask_sqlalchemy
    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
    
    # You can add pylint_flask but only if it is *AFTER* pylint_flask_sqlalchemy
    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
    

    Non-working versions

    # pylint_flask does not help, but can break it (see below)
    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
    
    # You can NOT add pylint_flask *BEFORE* pylint_flask_sqlalchemy
    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
    
    # CAUTION: These will disable pylint silently altogether!
    # Do not use dash (-) but underscore (_)!
    "python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy", "pylint-flask"]
    "python.linting.pylintArgs": ["--load-plugins", "pylint-flask"]
    "python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy"]
    
    

    Details for those who are interested

    pylint_flask_sqlalchemy

    The pylint-flask-sqlalchemy1 was created specifically to fix this2. You can enable it by adding it to --load-plugins of pylint. In command line this would be

    python -m pylint --load-plugins pylint_flash_sqlalchemy <mymodule.py>
    

    and in VS Code (Settings (JSON)):

    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
    

    1Also mirrored to GitHub: https://github.com/anybox/pylint_flask_sqlalchemy
    2See this comment on pylint Issue tracker.

    pylint_flask

    pylint-flask is pylint plugin for Flask. It has nothing to do with Flask-SQLAlchemy and it does not even try to solve the false positive issues pylint has with Flask-SQLAlchemy3. The only possibility to use pylint-flask to "make the errors disappear" is to load it with erroneusly with dashes, which makes the whole pylint to be disabled.

    It seems that pylint-flask must be loaded after pylint-flas-sqlalchemy; I tested with my setup, and for some reason

    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
    

    will not work, but

    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
    

    will. So the order of loading plugins matters.

    3 See the code for yourself: pylint-flask source & pylint-flask-sqlaclhemy source

    Caution: Do not remove your linting accidentally

    As the documentation of pylint-flask and pylint-flask-sqlalchemy says, the names in the argument --load-plugins should be written with underscores; If you use

    "python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
    

    in VS Code, the errors will be gone, but so will be all of your linting as the pylint crashes silently in the background.

    Installing pylint-flask-sqlalchemy

    pip install pylint-flask-sqlalchemy
    

    Used versions

    Flask                   1.1.2  
    Flask-SQLAlchemy        2.4.4 
    pylint                  2.5.3
    pylint-flask            0.6
    pylint-flask-sqlalchemy 0.2.0
    

    See also

    • Discussion on pylint GitHub issue: "Problem with Flask-SQLAlchemy, cannot find valid and existing property in SQLAlchemy object."
    0 讨论(0)
  • 2020-12-13 02:59
    pip install pylint-flask
    

    In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json as below:

    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
    
    0 讨论(0)
  • 2020-12-13 03:03

    EDIT: After read and try np8's answer my previous answer is wrong there is a package you have to install, which is pylint-flask-sqlalchemy

    so the answer will be

    on your project directory find folder .vscode (if you dont have it, just create it) then create file settings.json and add this line

    {
        # You have to put it in this order to make it works
        "python.linting.pylintArgs": [
            "--load-plugins",
            "pylint_flask_sqlalchemy",
            "pylint_flask",                 # This package is optional
        ]
    }
    

    You also need to have pylint-flask-sqlalchemy and if you want to use pylint-flask install on your current python environment:

    pip install pylint-flask-sqlalchemy
    pip install pylint-flask
    
    0 讨论(0)
  • 2020-12-13 03:03

    For Windows, this works: In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json -> and add this code after comma below existing settings:

        "python.linting.pylintArgs": [
            "--load-plugins",
            "pylint-flask"
        ]
    
    0 讨论(0)
  • 2020-12-13 03:11

    Open the Command Palette (Command+Shift+P on macOS and Ctrl+Shift+P on Windows/Linux) and type in one of the following commands:

    Python: Select Linter
    

    Switch from PyLint to flake8 or other supported linters.

    0 讨论(0)
  • 2020-12-13 03:13

    I've just encountered this issue. Neither of the suggested solutions worked for me, but the following does.

    First, install these modules:

    pip install pylint-flask
    pip install pylint-flask-sqlalchemy
    

    Then, in Visual Studio Code, you need to add the following to your settings.json file:

    "python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
    
    0 讨论(0)
提交回复
热议问题