-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to INSERT/UPDATE to Postgres Database on Heroku #118
Comments
I'm also affected by the issue described by @99nsx. The CS50 logger showed successful/green INSERTS/UPDATES/DELETES for my postgres database but those transactions were never actually committed or written to the database even though it works fine with SQLite. The same behavior occurred on a local postgres database. My fix: used SQL Alchemy and re-wrote all of my SQL statements. One tip to others who run into this is to make a helper function that does what line 328 - 343 does in the CS50 SQL library so that you get a list of dictionary objects with column names as the keys (i.e. the same behavior you're use to with CS50s library). Copy/pasting my helper function for clarity:
|
Ah, sorry about that. We're going to try to fix this one asap! |
Fixed by #122. |
After completing the CS50 Finance assignment, I attempted to move the application to Heroku. I converted the SQLite3 database over to Postgres. I am able to connect to the Heroku database using:
from CS50 import SQL
db = SQL("Heroku---URI")
SELECT statements do work and does retrieve the requested data. However, INSERT and UPDATE statements did not work for me. I was able to INSERT and UPDATE to the database using my computer's command line, as well as from pgAdmin 4.
Finally, I was able to get my CS50 Finance working by importing the sqlalchemy module instead, and adding .fetchall() to the end of SELECT statements and after INSERT/UPDATE statements I added the db.commit() statement in a line below it to save the changes.
I didn't see any additional notes (such as .commit()) in the documentation on how to get the CS50 module to work with a Postgres database. Sorry in advance if there's something that I missed. CS50 is such a tremendous class by the way, it's absolutely brilliant! 👍
The text was updated successfully, but these errors were encountered: