FLASKFM Step 13 Create DB issue

In step 13, I can’t get db.create_all() to work. When I reference the ‘db’ variable in terminal I get “”, so I assume it’s at least creating and recognizing the db instance. There is no error when I run db.create_all() but it also doesn’t seem to create a .db* extension.

from flask import Flask, render_template
#import SQLALchemy
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
#set the SQLALCHEMY_DATABASE_URI key
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = 'sqlite:///song_library.db'
app.config['SECRET_KEY'] = 'you-will-never-guess'
#create an SQLAlchemy object named `db` and bind it to your app
db = SQLAlchemy(app)
#a simple initial greeting
@app.route('/')
@app.route('/index')
def greeting():
    return render_template('greeting.html')

# app name 
@app.errorhandler(404) 
def not_found(e): 
  return render_template("404.html") 

#uncomment the code below here when you are done creating database instance db and models
import routes

I noticed your app.config for sqlalchemy for the database is slightly off. Check the documentation here for reference: Configuration — Flask-SQLAlchemy Documentation (2.x)

If you make the fix your code should work.

1 Like

I had a feeling it was something silly like that, thank you!

Any tips for sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed?

Most of the advice I’ve read says to delete the DB and try again, but I keep ending up with this error.

What’s your code look like now? This warrants a new thread also so people with similar errors can find this issue specifically :slight_smile:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.