Reputation: 53
I'm new to Python and still learning the basics. When running my program, it returns this error and I can't find the solution to this.
My codes are as follows:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
...
class Illness:
__tablename__ = "list_illnesses"
id = db.Column(db.Integer, primary_key=True)
illness = db.Column(db.String, nullable=False)
def __init__(self, illness):
self.illness = illness
import csv
import os
from flask import Flask, render_template, request
from models import *
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("DATABASE_URL")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.init_app(app)
def main():
f = open("illnesses.csv")
reader = csv.reader(f)
for name in reader:
foo = Illness(illness=name[0])
db.session.add(foo)
db.session.commit()
if __name__ == "__main__":
with app.app_context():
main()
illnesses.csv
only contains one illness name per line. I have been searching for hours but I can't seem to find the problem.
Upvotes: 1
Views: 1159
Reputation: 24966
It's probably significant that
class Illness:
isn't a subclass of db.Model
.
Upvotes: 1