Python - TypeError: Integer required

I am trying to create a database to keep users and climb with one-to-many relationships from users to climb the user.

class Climb(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime)
    name = db.Column(db.String(64))
    flash = db.Column(db.Boolean)
    notes = db.Column(db.Text)
    type_of_climb = db.Column(db.String(32))
    difficulty = db.Column(db.String(5))
    location = db.Column(db.String(64))
    favorite = db.Column(db.Boolean)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __init__(self, climb_date, name, flash, notes, type_of_climb, difficulty, location, favorite, user_id):
        set_date = datetime.strptime(climb_date, '%Y%m%d').date()
        self.date = set_date
        self.name = name
        self.flash = flash
        self.notes = notes
        self.type_of_climb = type_of_climb
        self.difficulty = difficulty
        self.location = location
        self.favorite = favorite
        self.user_id = user_id

      

I am trying to test a database using the Python console in PyCharm. I have successfully created a user and am trying to add ascent to the database, but keep getting "TypeError: integer required" when I use the following set of commands:

>>> from flask import Flask
>>> from app import app, db
>>> db.create_all()
>>> from app import User, Climb
>>> c = Climb('2015-05-02', 'Climb so high', 1, 'Made it happen', 'Trad', '5.8', 'Nepal', 0, 1)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<string>", line 4, in __init__
  File "/home/logan/Desktop/DEV/git/Climb-On/climb-on-api/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 269, in _initialize_instance
    return manager.original_init(*mixed[1:], **kwargs)
  File "/home/logan/Desktop/DEV/git/Climb-On/climb-on-api/app.py", line 50, in __init__
    self.flash = flash
TypeError: an integer is required

      

I am completely confused as to how I am getting this error (flash is the third parameter passed and my account 1 is an integer).

Any help is greatly appreciated.

+3


source to share


1 answer


It is possible that the corresponding column of the table in the database is not needed by the required SQLAlchemy type.



0


source







All Articles