I've made a simple code using python, where with the help of Flask_sqlalchemy I am trying to create 2 tables in a database which is being hosted by Heroku.

The file db.py contains my table details

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class Flight(db.Model):
    __tablename__ = "flights"
    id = db.Column(db.Integer, primary_key=True)
    origin = db.Column(db.String, nullable=False)
    destination = db.Column(db.String, nullable=False)
    duration = db.Column(db.Integer, nullable=False)

class Passenger(db.Model):
    __tablename__ = "passengers"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    flight_id = db.Column(db.Integer, db.ForeignKey("flights.id"), nullable=False)

And another file called test.db to call db.py

import os

from flask import Flask, render_template, request
from model import *

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "postgres://neakxnxnwavgux:f4c7ce2990ae0a285542ef4989fe25482bd26f66ad2f47b69b6b4c3d1acd2f88@ec2-52-86-73-86.compute-1.amazonaws.com:5432/doa4533066h0a"


def main():

if __name__ == "__main__":
    with app.app_context():

These aren't exactly my codes and I'm following the course web development with python and javascript where i was able to get these codes, however I'm stuck with this as an error appears when i run test.db

NameError: name 'db' is not defined

I had an import error saying that models doesn't exist and ran the code pip install pymodel in terminal . But now im stuck with a bigger problem that doesnt allow me to continue.


You must log in to answer this question.