如何运行sqlacodegen?

Gol*_*Jer 3 python sqlalchemy sqlacodegen

我不明白为什么我不能运行sqlacodegen.我希望用它来从我现有的PostgreSQL数据库创建一个SQLAlchemy模型.它不会运行.

当我打字sqlacodegen --help求助时,我得到:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bad operand type for unary -: '_Helper'
Run Code Online (Sandbox Code Playgroud)

基本说明在这里.

Ant*_*ala 17

这是因为你在Python shell中这样做了:

>>> import sqlacodegen
>>> sqlacodegen --help
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bad operand type for unary -: '_Helper'
Run Code Online (Sandbox Code Playgroud)

您应该sqlacodegen --helpUnix命令shell/Windows命令提示符下执行:

% sqlacodegen --help
usage: sqlacodegen [-h] [--version] [--schema SCHEMA] [--tables TABLES]
                   [--noviews] [--noindexes] [--noconstraints] [--nojoined]
                   [--noinflect] [--outfile OUTFILE]
                   [url]

Generates SQLAlchemy model code from an existing database.

positional arguments:
  url                SQLAlchemy url to the database

optional arguments:
  -h, --help         show this help message and exit
  --version          print the version number and exit
  --schema SCHEMA    load tables from an alternate schema
  --tables TABLES    tables to process (comma-separated, default: all)
  --noviews          ignore views
  --noindexes        ignore indexes
  --noconstraints    ignore constraints
  --nojoined         don't autodetect joined table inheritance
  --noinflect        don't try to convert tables names to singular form
  --outfile OUTFILE  file to write output to (default: stdout)
Run Code Online (Sandbox Code Playgroud)

那么实际命令的一个例子是:

% sqlacodegen --outfile models.py \
postgresql://gollyjer:swordfish@localhost:5432/mydatabase
Run Code Online (Sandbox Code Playgroud)

gollyjer:swordfish格式在哪里user:password.