Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:49:20+00:00 2026-06-09T10:49:20+00:00

I’m following the Flask-SQLAlchemy tutorial. I have Flask 0.9, sqlalchemy 0.7.8 and flask-sqlalchemy 0.16

  • 0

I’m following the Flask-SQLAlchemy tutorial. I have Flask 0.9, sqlalchemy 0.7.8 and flask-sqlalchemy 0.16 on python 2.6. (and I work with eclipse)

(The tuto is here : http://packages.python.org/Flask-SQLAlchemy/models.html)

I have 2 classes : a man and a wallet. There is a 1-1 relationship. (Each man has his own wallet)

class Man(db.Model):
    sid = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=False)
    wallet = db.relationship('Wallet', backref='man', lazy='dynamic', uselist=False)

    def __init__(self, wallet):
        self.wallet = wallet

class Wallet(db.Model):
    sid = db.Column(db.Integer, primary_key=True)
    account = db.Column(db.Integer)
    manId = db.Column(db.Integer, db.ForeignKey('man.sid'))

    def __init__(self, account):
        self.account = account

In my “main” module, I create my database :

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:PATH'
db = SQLAlchemy(app)

In this very same module, I try to attach a Wallet to a Man :

if __name__ == "__main__":
    db.create_all() 
    w1 = Wallet(132)
    w2 = Wallet(18)
    db.session.add(w1)
    db.session.add(w2)
    db.session.commit()
    man1 = Man(w1)
    db.session.add(man1)
    db.session.commit()

But I get this error :

TypeError: 'Wallet' object is not iterable

I fail to understand why such an error appears. What is the right way of adding a mapped object ?

PS : I’ve been on the SQLAlchemy tutorial and I believe that they would declare things differently :

class Man(db.Model):
    sid = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=False)
    wallet = db.relationship('Wallet', backref='man', lazy='dynamic', uselist=False)
    manId = db.Column(db.Integer, db.ForeignKey('man.sid'))
    def __init__(self, wallet):
        self.wallet = wallet

class Wallet(db.Model):
    sid = db.Column(db.Integer, primary_key=True)
    account = db.Column(db.Integer)

    def __init__(self, account):
        self.account = account

Which tutorial should I trust ?

Thank you very much !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:49:22+00:00Added an answer on June 9, 2026 at 10:49 am

    I fail to understand why such an error appears. What is the right way of adding a mapped object ?

    Notice that when you configure you wallet relationship you use lazy=”dynamic” option. This way you are setting up a dynamic relationship. As it is designed to be used with large collections it doesn’t really makes much sense to use it with one-to-one relationship.

    At the same time it alters the way you can assign to your scalar relationship, i.e. you cannot assing your single object directly:

    self.wallet = wallet
    

    but you must use an iterable

    self.wallet = [wallet]
    

    So you have two solutions here: either assign collection of one element as shown above or better yet stop using dynamic collections for this relationship.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.