Just starting with sqlacodegen: wrong command?

976 views
Skip to first unread message

Javier Garcia

unread,
Jun 14, 2022, 12:06:46 PM6/14/22
to sqlalchemy
Hi,

I have tried to run something like this:

sqlacodegen --generator tables mysql+pymysql://user:password@localhost/dbname

but I get:

usage: sqlacodegen [-h] [--version] [--schema SCHEMA] [--tables TABLES] [--noviews] [--noindexes] [--noconstraints] [--nojoined] [--noinflect] [--noclasses] [--nocomments] [--outfile OUTFILE] [url]
sqlacodegen: error: unrecognized arguments: --generator mysql+pymysql://root:*******@localhost/test_user

My sqlacodegen version is 2.3.0.

Any help?

Simon King

unread,
Jun 14, 2022, 12:21:31 PM6/14/22
to sqlal...@googlegroups.com
Based on the CHANGES file, it looks like --generator is a new option in v3.0.0:


Simon

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
http://www.sqlalchemy.org/
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/6bea9449-3c19-491f-ace7-c17a8440a03an%40googlegroups.com.

Javier Garcia

unread,
Jun 14, 2022, 12:25:08 PM6/14/22
to sqlalchemy
Thanks Simon, do you know how could I install that version as when I upgrade the sqlacodegen I still get the version 2.3.0?

Javier

Javier Garcia

unread,
Jun 14, 2022, 12:32:22 PM6/14/22
to sqlal...@googlegroups.com
This is what I'm getting when I try to upgrade to 3.0.0b3.

(venv) jgarcia@Javier-PC:/var/www$ sudo pip install sqlacodegen==3.0
ERROR: Could not find a version that satisfies the requirement sqlacodegen==3.0 (from versions: 1.0.0, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 2.0.0, 2.0.1, 2.1.0, 2.2.0, 2.3.0, 3.0.0b1, 3.0.0b2, 3.0.0b3, 3.0.0rc1)
ERROR: No matching distribution found for sqlacodegen==3.0
(venv) jgarcia@Javier-PC:/var/www$ sudo pip install sqlacodegen==3.0.0b3
Collecting sqlacodegen==3.0.0b3
  Downloading sqlacodegen-3.0.0b3-py3-none-any.whl (19 kB)
Requirement already satisfied: inflect>=4.0.0 in /usr/local/lib/python3.8/dist-packages (from sqlacodegen==3.0.0b3) (5.6.0)
Requirement already satisfied: SQLAlchemy>=1.4.0 in /usr/local/lib/python3.8/dist-packages (from sqlacodegen==3.0.0b3) (1.4.37)
Collecting importlib-metadata; python_version < "3.10"
  Downloading importlib_metadata-4.11.4-py3-none-any.whl (18 kB)
Requirement already satisfied: greenlet!=0.4.17; python_version >= "3" and (platform_machine == "aarch64" or (platform_machine == "ppc64le" or (platform_machine == "x86_64" or (platform_machine == "amd64" or (platform_machine == "AMD64" or (platform_machine == "win32" or platform_machine == "WIN32")))))) in /usr/local/lib/python3.8/dist-packages (from SQLAlchemy>=1.4.0->sqlacodegen==3.0.0b3) (1.1.2)
Collecting zipp>=0.5
  Downloading zipp-3.8.0-py3-none-any.whl (5.4 kB)
Installing collected packages: zipp, importlib-metadata, sqlacodegen
  Attempting uninstall: sqlacodegen
    Found existing installation: sqlacodegen 2.3.0
    Uninstalling sqlacodegen-2.3.0:
      Successfully uninstalled sqlacodegen-2.3.0
Successfully installed importlib-metadata-4.11.4 sqlacodegen-3.0.0b3 zipp-3.8.0
(venv) jgarcia@Javier-PC:/var/www$ sqlscodegen --version

Command 'sqlscodegen' not found, did you mean:

  command 'sqlacodegen' from deb sqlacodegen (1.1.6-2build1)

Try: sudo apt install <deb name>

(venv) jgarcia@Javier-PC:/var/www$ sqlacodegen --version
2.3.0

Val Huber

unread,
Jun 14, 2022, 8:38:33 PM6/14/22
to sqlalchemy
Not sure how this may match your needs, but API Logic Server includes a version of sqlacodegen to create an executable Flask project, including a web app, API, and rules-based logic.  It includes a Command Line Utility that provides SQLAlchemy URI examples:

(venv) val@Vals-MacBook-Pro-16 ApiLogicServer % ApiLogicServer examples


Welcome to API Logic Server 5.02.22


Creates and optionally runs a customizable ApiLogicServer project


Examples:

  ApiLogicServer create-and-run

  ApiLogicServer create-and-run --db_url=sqlite:///nw.sqlite

  ApiLogicServer create-and-run --db_url=mysql+pymysql://root:p@mysql-container:3306/classicmodels --project_name=/localhost/docker_db_project

  ApiLogicServer create-and-run --db_url=mssql+pyodbc://sa:posey386!@localhost:1433/NORTHWND?driver=ODBC+Driver+17+for+SQL+Server&trusted_connection=no

  ApiLogicServer create-and-run --db_url=postgresql://postgres:p...@10.0.0.234/postgres

  ApiLogicServer create --project_name=my_schema --db_url=postgresql://postgres:p@localhost/my_schema

  ApiLogicServer create --db_url=postgresql+psycopg2://postgres:password@localhost:5432/postgres?options=-csearch_path%3Dmy_db_schema

  ApiLogicServer create --project_name=Chinook \

    --host=ApiLogicServer.pythonanywhere.com --port= \

    --db_url=mysql+pymysql://ApiLogicServer:***@ApiLogicServer.mysql.pythonanywhere-services.com/ApiLogicServer\$Chinook


Where --db_url defaults to supplied sample, or, specify URI for your own database:

   SQLAlchemy Database URI help: https://docs.sqlalchemy.org/en/14/core/engines.html

   Other URI examples:           https://github.com/valhuber/ApiLogicServer/wiki/Testing

   Install Guide:                https://github.com/valhuber/ApiLogicServer/wiki/Quick-Start#install-guide

 

Docs: https://github.com/valhuber/ApiLogicServer#readme



(venv) val@Vals-MacBook-Pro-16 ApiLogicServer % 


Simon King

unread,
Jun 15, 2022, 4:42:53 AM6/15/22
to sqlal...@googlegroups.com
Here's the command you ran:

(venv) jgarcia@Javier-PC:/var/www$ sudo pip install sqlacodegen==3.0.0b3

The "(venv)" at the beginning of your prompt suggests that you are in an activated virtualenv. But when you run "sudo pip", you are installing the package globally. You now have 2 different versions of sqlacodegen installed in different locations.

You should probably have run "pip install" *without* "sudo". If you *need* sudo (because your virtualenv is owned by root), you must ensure that you run the "pip" that is installed in the virtualenv, by using an absolute path.

Hope that helps,

Simon

Javier Garcia

unread,
Jun 15, 2022, 6:56:07 AM6/15/22
to sqlalchemy
Thanks both!
Reply all
Reply to author
Forward
0 new messages