techwithtim / Flask-Web-App-Tutorial

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

Cannot Create Database #163

Open JC-Lord opened 3 weeks ago

JC-Lord commented 3 weeks ago

I am admittedly extremely new to Python and coding in general, however, I was following along with this tutorial a day ago and everything was going well up until it came time to create the database.

My code is as follows:

from flask import Flask from flask_sqlalchemy import SQLAlchemy from os import path'

db = SQLAlchemy() DB_NAME = "database.db"

def create_app(): app = Flask(name) app.config['SECRET_KEY'] = 'domine' app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}' db.init_app(app)

from .views import views
from .auth import auth

app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')

from .models import User, Note

with app.app_context():
    db.create_all()

return app

def create_database(app): if not path.exists('website/' + DB_NAME): db.create_all(app=app) print('Created Database!')

I have looked over stack overflow and tried a few things here and there, however, I just seem to run into more errors. At one point what seemed like a database was created in the instance folder of my project, however, it was not named what was expected and I have since been unable to replicate its creation.

ThatGabrieleC commented 2 weeks ago

What is the error you receive? Also please post more code, may it's due to other pages