Creating SQLAlchemy model instance raises "TypeError: __init__() takes exactly 1 argument"
<p>I have defined a model with Flask-SQLAlchemy and want to insert a row with it in a Flask view. When I try to create the instance, I get <code>TypeError: __init__() takes exactly 1 argument (5 given)</code>. I think the issue has to do with the constructor but the <a href="http://flask-sqlalchemy.pocoo.org/2.1/queries/" rel="nofollow">docs</a> don't really explain what is required. How do I create an instance of my model while passing data to it?</p>

<pre><code>class Update(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    tracking_number = db.Column(db.Integer)
    date = db.Column(db.DateTime)
    status = db.Column(db.String(80))
    location = db.Column(db.String(80))

@app.route('/put_update')
def put_update():
    update = Update('trackingid', '2016-08-30 22:48:00', 'status', 'location')
    db.session.add(update)
    db.session.commit()
</code></pre>

<p>SQLAlchemy provides a default constructor that takes keyword arguments and assigns them to the instance.</p>

<pre><code>Update(trackingnumber='trackingid', ...)
</code></pre>

<p>This is typically all you need, and is convenient for uses like unpacking data you get from a form (as long as the field names match up).</p>

<p>If you don't want to pass keywords, you can override <code>__init__</code> to take whatever arguments in whatever order you want.  For example, if <code>Update</code> always needs <code>trackingnumber</code> and you want to pass it as the first positional argument:</p>

<pre><code>class Update(db.Model):
    ...

    def __init__(self, trackingnumber, **kwargs):
        self.trackingnumber = trackingnumber
        super().__init__(**kwargs)
</code></pre>

<p>This can be useful in some situations but typically you should just stick with the default of passing keyword arguments.</p>

python flask sqlalchemy flask-sqlalchemy