trying to build to-do list app with python , flask and sqlalchemy; when creating a table to database i got this error
i run this command
'from app import db'
I receive this warning :
C:\Users\Mahmoud\.virtualenvs\to-do_list_flask-Gr0Wv-V5\lib\site-packages\sqlalchemy\ext\declarative\base.py:361: SAWarning: Attribute 'item' on class <class 'app.todo'> appears to be a non-schema 'sqlalchemy.sql.column()' object; this won't be part of the declarative mapping
% (key, cls)
C:\Users\Mahmoud\.virtualenvs\to-do_list_flask-Gr0Wv-V5\lib\site-packages\sqlalchemy\ext\declarative\base.py:361: SAWarning: Attribute 'date' on class <class 'app.todo'> appears to be a non-schema 'sqlalchemy.sql.column()' object; this won't be part of the declarative mapping
% (key, cls)
if i do excute db.create_all()
the table only has an id column
my script:
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres://postgres:123456@localhost/todo_list'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class todo(db.Model):
__tablename__ = 'todo'
id = db.Column(db.Integer, primary_key=True)
item = db.column(db.String(500))
date = db.column(db.Date)
def __init__(self, item, date):
self.item = item
self.date = date
@app.route('/')
def index():
return render_template('index.html')
@app.route('/submit', methods = ['POST'])
def submit():
if request.method == 'POST':
item = request.form['item']
date = request.form['date']
data = todo(item, date)
db.session.add(data)
db.session.commit()
return render_template('index.html', item = item, date = date)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8000, debug=True)
I was having this same error. Turns out its just a litte syntax error. Column should be upcase so:
id = db.Column(db.Integer, primary_key=True)
item = db.Column(db.String(500))
date = db.Column(db.Date)
Should fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With