1

I have issues with my code, trying to setup SQLAlchemy database in flask using python. Code:

Thanks for the help.

Tried to reinstall SQLAlchemy.

I'm using a corporate laptop, shouldn't be a problem?

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'
SuperShoot
  • 9,880
  • 2
  • 38
  • 55
Rod Sanchez
  • 11
  • 1
  • 2

1 Answers1

8

For the Warning:

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 '

Set the 'SQLALCHEMY_TRACK_MODIFICATIONS' to True / False. Preferably False by adding the below line

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

Immediately after instantiation of the Flask app, i.e., after the below line:

app = Flask(__name__)

For the Error:

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

There is a typo error, the type is db.DateTime.

gksingh
  • 277
  • 3
  • 6