retrofun
retrofun copied to clipboard
Alembic raising an error when creating the migration script for a postgreSQL DB
I am working through the book (Kindle version) and got stuck when introducing Alembic as the create migration command raises an error as follows:
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/configparser.py", line 374, in before_set raise ValueError("invalid interpolation syntax in %r at " ValueError: invalid interpolation syntax in 'postgresql+psycopg2://retrofun:123.%[email protected]:5432/retrofun' at position 35
I'm running a postgreSQL database on another computer on my local network. I tried copying the line used for SQLAlchemy to connect with no luck.
I know I could be missing something but I could find a suitable solution when googling for a solution, hence the need to reach out to you.
I am adding the env.py (as a .txt file as GitHub doesn't allow .py files)
@afcristia The "%" that you have in your password is causing this, because this character is used for interpolation. Use "%%" to escape it.
thanks for your prompt reply. However, I'am affraid that's not it, as my password doesn't have a % sign.
env.txt
I'm attaching my .env file (with a .txt extension) so you can check. Alembic is changing ".," in my password for ".%2C" somewhere with its code, but I have no idea where it could be.
To determine where is this happening it would be useful to see the complete stack trace of the error.
In env.py, change this line:
config.set_main_option("sqlalchemy.url", engine.url.render_as_string(
hide_password=False))
to this:
config.set_main_option("sqlalchemy.url", engine.url.render_as_string(
hide_password=False).replace('%', '%%'))
Let me know if that helps!
I just tried it and worked perfectly.
Thanks so much.