'Flask SQLAlchemy: TypeError: Incompatible collection type: bool is not list-like

I have a User Model, and I have a Team Model. A team can have two users, and is linked by two foreign keys. I have created relationships with back_populates on each side, however whenever I try to seed my users I get this error: TypeError: Incompatible collection type: bool is not list-like

I am having trouble understanding what Boolean value it is referring to, and what the error even is in the first place. I tried adding the default value to the end of my seed, and also tried inserting the relationship as a list and it hasn't fixed anything. Anyways, heres my code.

#User Model
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), unique=True, nullable=False)
    first_name = db.Column(db.String(50), nullable=False)
    last_name = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(20), nullable=False)
    phone_number = db.Column(db.String(15), nullable=False)
    team_lead = db.Column(db.Boolean, nullable=False)
    image = db.Column(db.String(255))
    online = db.Column(db.Boolean, default=False)



    team_lead = relationship('Team', foreign_keys=[Team.team_lead_id], back_populates='lead')
    team_member = relationship('Team', foreign_keys=[Team.team_member_id], back_populates='member')

#Team Model
class Team(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    team_lead_id = db.Column(db.Integer, ForeignKey('user.id'))
    team_member_id = db.Column(db.Integer, ForeignKey('user.id'))
    tower_id = db.Column(db.Integer, ForeignKey('tower.id'))
    jobsite_id = db.Column(db.Integer, ForeignKey('job_site.id'))
    job_type = db.Column(db.String, nullable=False)


    tower = relationship('Tower', back_populates='team_id')
    lead = relationship('User', foreign_keys=[team_lead_id], back_populates='team_lead')
    member = relationship('User', foreign_keys=[team_member_id], back_populates='team_member')
    team_jobsite = relationship('JobSite', back_populates='teams')



#USERS SEED
def seed_users():
    # image='https://fionacapstonebucket.s3.us-west-1.amazonaws.com/defaults/c203d7ca558d417b9aea8cd102ae32cf.jpg'
    dan = User(
        email='[email protected]', first_name='Dan', last_name='Down', password='password', phone_number='408-924-6314', team_lead=False, image='https://fionacapstonebucket.s3.us-west-1.amazonaws.com/defaults/09fb955ae10c4aff9708b4d6293fd1d8.png')
    karis = User(
        email='[email protected]', first_name='Karis', last_name='Gardner', password='password', phone_number='408-917-6314', team_lead=True, image='https://fionacapstonebucket.s3.us-west-1.amazonaws.com/defaults/09fb955ae10c4aff9708b4d6293fd1d8.png')
    tony = User (
        email='[email protected]', first_name='Tony', last_name='Trashman', password='password', phone_number='408-918-6314', team_lead=True, image='https://fionacapstonebucket.s3.us-west-1.amazonaws.com/defaults/09fb955ae10c4aff9708b4d6293fd1d8.png')
    mike = User (
        email='[email protected]', first_name='Mike', last_name='Pandas', password='password', phone_number='408-919-6314', team_lead=False, image='https://fionacapstonebucket.s3.us-west-1.amazonaws.com/defaults/09fb955ae10c4aff9708b4d6293fd1d8.png')
    darren = User (
        email='[email protected]', first_name='Darren', last_name='kong', password='password', phone_number='408-901-6314', team_lead=True, image='https://fionacapstonebucket.s3.us-west-1.amazonaws.com/defaults/09fb955ae10c4aff9708b4d6293fd1d8.png')
    chris = User (
        email='[email protected]', first_name='Chris', last_name='Threadgill', password='password', phone_number='508-761-2443', team_lead=False, image='https://fionacapstonebucket.s3.us-west-1.amazonaws.com/defaults/09fb955ae10c4aff9708b4d6293fd1d8.png')
    celeste = User (
        email='[email protected]', first_name='Celesta', last_name='Winterton', password='password', phone_number='615-744-3351', team_lead=False, image='https://fionacapstonebucket.s3.us-west-1.amazonaws.com/defaults/09fb955ae10c4aff9708b4d6293fd1d8.png')
    

    
db.session.add(dan)
db.session.add(karis)
db.session.add(tony)
db.session.add(mike)
db.session.add(darren)
db.session.add(chris)
db.session.add(celeste)

db.session.commit()



#Team SEED
def seed_teams():
    Team1 = Team(
           jobsite_id= 1, team_lead_id=1, team_member_id=2, tower_id=1, job_type='Fiberglass')
    Team2 = Team(
           jobsite_id= 2, team_lead_id=3, team_member_id=4, tower_id=1, job_type='Fiberglass')

    
    db.session.add(Team1)
    db.session.add(Team2)
    
    db.session.commit()

This is the full error message:

     * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  warnings.warn(FSADeprecationWarning(
Traceback (most recent call last):
  File "/Users/wning/Coding/windVentory/venv/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/flask/cli.py", line 985, in main
    cli.main()
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/flask/cli.py", line 579, in main
    return super().main(*args, **kwargs)
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/flask/cli.py", line 427, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/wning/Coding/windVentory/flaskproject/seeds/__init__.py", line 17, in seed
    seed_users()
  File "/Users/wning/Coding/windVentory/flaskproject/seeds/users.py", line 8, in seed_users
    brendan = User(
  File "<string>", line 4, in __init__
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/sqlalchemy/orm/state.py", line 480, in _initialize_instance
    manager.dispatch.init_failure(self, args, kwargs)
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/sqlalchemy/orm/state.py", line 477, in _initialize_instance
    return manager.original_init(*mixed[1:], **kwargs)
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 1157, in _declarative_constructor
    setattr(self, k, kwargs[k])
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py", line 459, in __set__
    self.impl.set(
  File "/Users/wning/Coding/windVentory/venv/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py", line 1563, in set
    raise TypeError(
TypeError: Incompatible collection type: bool is not list-like

Thanks in advance. This is my first question, so any feedback is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source