SQLAlchemy-Notes

1. What is SQLAlchemy

2. Install

2.1. Install Tool sqlacodegen

  • sqlacodegen is a tool that will create SQLAlchemy model code from a DB.

    1. Install

      py -3 -m pip install sqlacodegen_v2
    2. Manually apply a fix:

      1. Open this file:

        C:\Users\<username>\AppData\Local\Programs\Python\Python3xx\Lib\site-packages\sqlacodegen\codegen.py (1)
        1 Replace with your username and specific Python version
      2. Find this import statement

        from inspect import ArgSpec
      3. Change it to:

        from inspect import getfullargspec

2.1.1. Usage

  1. Use to generate:

    SQLite Example
    C:\Users\<username>\AppData\Local\Programs\Python\Python3xx\Scripts\sqlacodegen sqlite:///C:/Users/<username>/Downloads/Portal_DB.db --outfile models_portal_db.py (1)
    1 Replace with your username and specific Python version

2.2. Install SQLAlchemy

Installing sqlacodegen from the previous step will also install the required SQLAlchemy packages.