python - Query returns different data when using MySQL versus SQLite -
when query following model sqlalchemy, don't expected result.
class user(db.model): __tablename__ = 'users' id = db.column(db.integer, primary_key=true) username = db.column(db.string(64), unique=true) def __repr__(self): return '<user %r>' % self.username
i created mysql table directly, committe data:
mysql> create table "users" (id integer, username varchar(64)); mysql> select * users; +------+-------------+---------+ | id | username | role_id | +------+-------------+---------+ | null | yzxu | null | | null | after | null | +------+-------------+---------+
when using mysql, sqlalchemy query returns none
.
>>> user.query.filter_by(username='after').all() [none]
when using sqlite, correct username returned.
>>> db.create_all() >>> db.session.add(user(username='after')) >>> db.session.commit() >>> user.query.filter_by(username='after').all() [<user u'after'>]
the mysql table created manually me without sqlalchemy. missing primary key set on id
.
Comments
Post a Comment