can anyone please help me with it. I was trying to use sqlacodegen with postgresql to autogenerate the database models from my database, but it is constantly showing me this import error
>sqlacodegen postgresql://postgres:j1234@localhost:4040/db1
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Scripts\sqlacodegen.exe\__main__.py", line 4, in <module>
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlacodegen\main.py", line 11, in <module>
from sqlacodegen.codegen import CodeGenerator
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlacodegen\codegen.py", line 9, in <module>
from inspect import ArgSpec
ImportError: cannot import name 'ArgSpec' from 'inspect' (C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\inspect.py)
i am working with python 3.11, postgresql, sqlalchemy 2.0.15, and sqlacodegen 2.3.0
I want to autogenerate database models from my database for my fastapi. I am also open to any kind of sqlacodegen alternatives
I encountered this issue as well. The problem arises because ArgSpec has been removed in Python 3.11.
The solution is to open the
/site-packages/sqlacodegen/codegen.pyfile in your text editor. Then, delete the line that includesfrom inspect import ArgSpecat line 9. Additionally, remove lines 486 and 488, replacing them withreturn False, and then run your command again. It should work without any issues.