Closed Alkasih closed 5 years ago
do not execute .all()
in your query = session.query(Rawlog).all()
. It returns a list, which explains the error. You must construct a query, and the lib executes in the end the all()
@Pegase745 Thank you for the respond. I actually had changed the way I query it by session.query().select_from(Rawlog)
And now it return another error
{"draw":"2","error":"int() argument must be a string or a number, not 'NoneType'","recordsFiltered":"322687","recordsTotal":"322687"}
I have tried this,
Rawlog.query.with_entities(Rawlog.id, Rawlog.one, Rawlog.two, Rawlog.three)
but the error is the same
{"draw":"2","error":"int() argument must be a string or a number, not 'NoneType'","recordsFiltered":"322687","recordsTotal":"322687"}
Could you paste the correct models.py
file please ? It's not clear between the one here, and the one on stackoverflow. It seems like an issue in your model definition, and not the way you query
@Pegase745 Thank you, again. Here is my model.
# coding: utf-8
from app import db
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.schema import FetchedValue
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import inspect, ForeignKey
#db = SQLAlchemy()
Base = declarative_base()
class Base(db.Model):
__abstract__ = True
id = db.Column(db.Integer, primary_key=True)
class Rawlog(Base):
__tablename__ = 'rawlogs'
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String(640, u'utf8_unicode_ci'), nullable=False)
sent = db.Column(db.DateTime, nullable=False)
received = db.Column(db.DateTime, nullable=False)
readable_content = db.Column(db.String(640), nullable=False)
hantu = db.Column(db.Integer, server_default=db.FetchedValue())
def __init__(id, content, sent, received, readable_content, hantu):
self.id = id
self.content = content
self.received = received
self.readable_content = readable_content
self.sent = sent
self.hantu = hantu
And here is the app db
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://sudo:password@hostandport/db'
app.config["SQLALCHEMY_ECHO"] = False
db = SQLAlchemy(app)
Have you tried something as simple as that ?
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Rawlog(db.Model):
__tablename__ = 'rawlogs'
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String(640, u'utf8_unicode_ci'), nullable=False)
sent = db.Column(db.DateTime, nullable=False)
received = db.Column(db.DateTime, nullable=False)
readable_content = db.Column(db.String(640), nullable=False)
hantu = db.Column(db.Integer, server_default=db.FetchedValue())
Yes, I just tried it, and the result is similar.
{"draw":"2","error":"int() argument must be a string or a number, not 'NoneType'","recordsFiltered":"322687","recordsTotal":"322687"}
Any idea, please? I am still struggling find the solution for this. Could it because it may never work with Flask?
It sure works as you can check the example flask_tut
in the examples folder and on branch v2 if you want a newer version.
You should use pdb and debug, I can't help more blindlessly
Happy New Year. How to upgrade the new version?
The new version is not released on pypi yet, so you can install it by cloning the right branch to your local machine and run python setup.py .
.
Closed old issue
I am using Flask
I always get error message
"error":"'list' object has no attribute 'add_columns'"
I tried to googling it, but seems no one have similar issue with me.I am using mysql.
`
And I always end up accessing it by passing draw parameter:
And it give result
Here is my model
`