SQLalchemy AttributeError: 'str' object has no attribute '_sa_instance_state'

前端 未结 3 1044
野性不改
野性不改 2020-12-10 10:54

I\'m trying to add an item to my database with SQLAlchemy + Python, but keep getting an error.

My database_setup.py:

class company(Base):
    __table         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 11:38

    I think the problem is in how you are defining the related company schema:

    JawboneUP3 = item(itemID = "1", name = "Jawbone UP3", description = "The latest UP!", 
                      category = "tracker", price = "$174.99", company = "Jawbone")
                                                               # HERE^
    

    The item constructor expects a company instance but you are passing a string value. Fix it:

    JawboneUP3 = item(itemID="1", 
                      name="Jawbone UP3", 
                      description="The latest UP!", 
                      category="tracker", 
                      price="$174.99", 
                      company=company(name="Jawbone"))
    

提交回复
热议问题