techwithtim / Flask-Web-App-Tutorial

Code for the note storing flask web app made during a YouTube video.
918 stars 1.01k forks source link

I've corrected the call to create_all(), but no database file is created #139

Closed ran-guin closed 7 months ago

ran-guin commented 7 months ago

I have updated the create_database function after googling the initial problem that others seem to have encountered with the create_app() call.

I no longer get any errors but there is no database file created.

(I did notice someone on a forum somewhere had trouble when trying to do this on a Mac, but no further explanation or solution) - I am running this on an old(ish) Macbook Air, though not sure why that would be a problem.

Here is the current function (which is being executed - ie the "Created Database" message is generated at runtime) ...

def create_database(app):
  if not path.exists('website/' + DB_NAME):
    with app.app_context():
      db.create_all()
      print('Created Database!')
ran-guin commented 7 months ago

I just realized that the database file is created in the instance/ directory.

This is fine, but it could probably be made more clear (along with the tweaks required to fix the create_all() command) that this is where it is going since this is not where it goes in the video.

Otherwise, I did find the video extremely useful and an excellent starting point for anyone wishing to get up and running quickly with python.

Thanks very much for putting this together !

ran-guin commented 7 months ago

Note: I'd propose putting updates regarding the above issues in the README.md file. (as well as any other tweaks that might be required for newer versions of flask/SQLAlchemy/Python etc). That could save people from having to search through the issues. ... just a constructive suggestion for what is otherwise a very well put together template.