我是Python的新手,仍然在学习基础知识。运行程序时,它将返回此错误,而我找不到解决方案。
我的代码如下:
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
每行仅包含一个疾病名称。我已经搜寻了几个小时,但似乎找不到问题。
答案 0 :(得分:1)
可能很重要
疾病类别:
不是db.Model
的子类。