Flask Travel Sites Project [Encountering Database Error]

In this project, Travel Sites, I am at the last step. I am working on the project in the Codecademy Learning Environment. But I cannot fully interact with the website to see if all my code is working properly because whenever I enter a route that performs a database query or commit, I get the following error:


sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed [SQL: INSERT INTO user (username, email, password) VALUES (?, ?, ?)] [parameters: (‘blabla’, ‘blabla@gmail.com’, None)] (Background on this error at: http://sqlalche.me/e/4xp6)

What can I try to do at this point?

This often happens when you change your database definitions in a way that conflicts with your previous definitions (to avoid future issues, look into migrations with Alembic/Flask-Migrate before making drastic changes to important databases).

From Miguel Grinberg’s book Flask Web Development (p.118, O’Reilly 2nd edition)

In the same way source code version control tools keep track of changes to source code files, a database migration framework keeps track of changes to a database schema, allowing incremental changes to be applied.

One option is to just start a whole new db file with your new definitions, if they’re solid it should work. Trying to recuperate is a different endeavour, and perhaps less interesting (sqlite - How to recover a corrupt SQLite3 database? - Stack Overflow).

Resources for migration: GitHub - miguelgrinberg/Flask-Migrate: SQLAlchemy database migrations for Flask applications using Alembic
Flask-Migrate — Flask-Migrate documentation

Thanks. Problem solved by deleting the .db file which existed at the start of the project and creating a new db using db.create_all().

I have new issues however. I’m having a hard time discerning what info i need to share so that other people can help me. What im experiencing is that I can add a user to the db, but I cannot login or authenticate. What ill say is that I compared my code against this guy’s code, who has deployed the Travel Site project on Heroku and it sort of looks like my code is pretty much the same as his (except for his additional modifications involving using PostgreSQL).

So my decision for now is to skip to the next part of the skill path, which is about deploying to Heroku, where I will try to do the same as that guy I linked, and we shall see if i did something wrong or if the project cannot be completed on the CC Learning Environment. I have not been able to find any mention on the forum of other people trying to accomplish this project on the CC Learning Environment.

Best bet is to share on github (with the reqs file for your specific version of things you’re using). At worst someone can try to replicate your error if they’re feeling generous.

The further you get on flask the less the CC LE is flexible because of the missing extra pane you need for information while testing.