Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQLalchemy issue
#1
I have been using sqlalchemy both within and without Flask and never had ant issues.
I know that my model is OK as I use it to populate my database.
However when trying to do a simple query, I'm getting improper results.
First I tested a standard select statement using DB Browser:
select CountyId from CountyInfo where StateAbbr = 'IL' and CountyName = 'Bond County';
and it returns the correct result '005'
then I try sqlalchemy.orm query and get wrong value (which happens to be in the first row of the table.
1
2
3
4
5
6
7
8
9
10
>>> from sqlalchemy.orm import sessionmaker
>>> import IL_Model
>>> tmap = IL_Model
>>> db = tmap.engine
>>> Session = sessionmaker(bind=db)
>>> session = Session()
>>> ci = tmap.CountyInfo
>>> county_id = session.query(ci.CountyId).filter(ci.StateAbbr == 'IL' and ci.CountyName == "Bond County").first()
>>> county_id
('001',)
001 is the first CountyId in the table, result should have been 005

I don't know if I'm just too tired and can't see what's wrong (been up most of the night), but I don't see what I am doing wrong?

I've done this sort of thing numerous times in the past and never had a problem.

Can anyone see my obvious mistake?
Reply


Messages In This Thread
SQLalchemy issue - by Larz60+ - Jun-01-2020, 10:48 AM
RE: SQLalchemy issue - by buran - Jun-01-2020, 11:01 AM
RE: SQLalchemy issue - by Larz60+ - Jun-01-2020, 11:03 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020