SQLALchemy增加了显著的过载。SQLAlchemy对象没有属性“dateTim”

2024-09-30 08:27:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码有问题,试图使用python在flask中设置SQLAlchemy数据库。代码:

谢谢你的帮助。在

尝试重新安装SQLAlchemy。在

我用的是公司的笔记本电脑,应该没问题吧?在

from flask import Flask, render_template, url_for
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db = SQLAlchemy(app)

class Todo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String(200), nullable=False)
    date_created = db.Column(db.DateTime, default=datetime

def __repr__(self):
    return '<Task %r>' % self.id

@app.route('/', methods=['POST', 'GET'])
def index():
    return render_template('index.html')

if __name__ == "__main__":
    app.run(debug=True)
(env) C:\Users\rodrigs\Documents\PythonFlaskApp>app.py
C:\Users\rodrigs\Documents\PythonFlaskApp\env\lib\site-packages\flask_sqlalchemy\__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
Traceback (most recent call last):
  File "C:\Users\rodrigs\Documents\PythonFlaskApp\app.py", line 9, in <module>
    class Todo(db.Model):
  File "C:\Users\rodrigs\Documents\PythonFlaskApp\app.py", line 13, in Todo
    date_created = db.Column(db.dateTime, default=datetime.utcnow)
AttributeError: 'SQLAlchemy' object has no attribute 'dateTime'

Tags: frompyimportappflaskdbdatetimesqlalchemy
1条回答
网友
1楼 · 发布于 2024-09-30 08:27:43

对于警告:

FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '

将“SQLALCHEMY_TRACK_MODIFICATIONS”设置为True/False。最好通过添加下面的一行来判断错误

^{pr2}$

在烧瓶应用程序实例化后,即在以下行之后:

app = Flask(__name__)

对于错误:

 date_created = db.Column(db.dateTime, default=datetime.utcnow)
AttributeError: 'SQLAlchemy' object has no attribute 'dateTime'

有一个打字错误,类型为数据库日期时间. 在

相关问题 更多 >

    热门问题