gpt4 book ai didi

python - 如何运行sqlacodegen?

转载 作者:行者123 更新时间:2023-12-02 18:00:22 24 4
gpt4 key购买 nike

我正在尝试运行 sqlacodegen 从现有 PostgreSQL 数据库创建 SQLAlchemy 模型。

它不会运行。当我输入 sqlacodegen --help 时,我得到:

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

基本说明是here .

如何让 sqlacodegen 运行?

最佳答案

这是因为你是在 Python shell 中执行此操作的:

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

您应该在 Unix 命令 shell/Windows 命令提示符中执行 sqlacodegen --help:

% 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)

实际命令的示例如下:

% sqlacodegen --outfile models.py \
postgresql://gollyjer:swordfish@localhost:5432/mydatabase

其中 gollyjer:swordfish 是您的凭据,格式为 user:password

关于python - 如何运行sqlacodegen?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28788186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com