I am trying to run a small app on apache2 server, the original database I used was Sqlite and now I am switching to Postgresql. The project uses Flask and Sqlalchemy and I get 500 Internal Error and error log says invalid input syntax for integer (items in name Column in Categories).
I have narrowed down the root of the problem down to the following lines but currently unable to solve the problem. addItem(DBSampleData.SampleItem)
def addItem(item):
for i in item:
items = Item(name=i[0], price=i[1], description=i[2],
category_ID=i[3], user_ID=i[4])
session.add(items)
session.commit
One of the SampleItem is:
('Maelstrom','2800',
'A hammer forged for the gods themselves, '
'Maelstrom allows its user to harness the '
'power of lightning.',
'Attack Speed',"guberland")
and the Categories DB setup part is:
class User(Base):
__tablename__ = 'user'
ID = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
class Categories(Base):
__tablename__ = 'categories'
ID = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
class Item(Base):
__tablename__ = 'item'
ID = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
description = Column(String(250))
price = Column(String(8))
category_ID = Column(Integer, ForeignKey('categories.ID'))
category = relationship(Categories)
user_ID = Column(Integer, ForeignKey('user.ID'))
user = relationship(User)
The part of error log from apache2 is:
[Tue Oct 31 16:17:18.814754 2017] [wsgi:error] [pid 1631:tid 140448423360256] [client 75.155.173.141:51827] psycopg2.DataError: invalid input syntax for integer: “Attack Damage”
where the "Attack Damage" is the Categories.name Thanks in advance!
IDtoCategoriessince you don't haveIDset to auto-increment. Also, you forgot the parenthesis onsession.commit()- kstullich