title: Why am I getting "TypeError: id() takes exactly one argument (0 given)"?
body: <p>I've created a <code>time_zones</code> table. When I try to populate it I get a <code>TypeError</code> saying I need to include an <code>id</code> value.</p>
  
  <p>The table from postgresql:</p>
  
  <pre><code>\d+ time_zones
                                                           Table "public.time_zones"
     Column   |            Type             |                        Modifiers                        | Storage  | Stats target | Description 
  ------------+-----------------------------+---------------------------------------------------------+----------+--------------+-------------
   id         | integer                     | not null default nextval('time_zones_id_seq'::regclass) | plain    |              | 
   name       | character varying(128)      | not null                                                | extended |              | 
   created_at | timestamp without time zone |                                                         | plain    |              | 
   updated_at | timestamp without time zone |                                                         | plain    |              | 
  Indexes:
      "time_zones_pkey" PRIMARY KEY, btree (id)
      "time_zones_name_key" UNIQUE CONSTRAINT, btree (name)
  Referenced by:
      TABLE "app_users" CONSTRAINT "app_users_time_zone_id_fkey" FOREIGN KEY (time_zone_id) REFERENCES time_zones(id)
  </code></pre>
  
  <p>The TimeZone class from <code>models.py</code>:</p>
  
  <pre><code>class TimeZone(db.Model):
    __table_name__ = 'time_zones'
  
    id = db.Column(db.Integer, db.Sequence('time_zones_id_seq'), primary_key=True, nullable=False)
    name = db.Column(db.String(128), nullable=False)
    created_at = db.Column(db.TIMESTAMP(timezone=False), default=_get_date)
    updated_at = db.Column(db.TIMESTAMP(timezone=False), onupdate=_get_date)
  </code></pre>
  
  <p>The <code>Alembic</code> migration file:</p>
  
  <pre><code>def upgrade():
    op.create_table('time_zones',
                    sa.Column('id', sa.Integer, primary_key=True, nullable=False),
                    sa.Column('name', sa.String(128), nullable=False, unique=True),
                    sa.Column('created_at', sa.TIMESTAMP(timezone=False), default=_get_date),
                    sa.Column('updated_at', sa.TIMESTAMP(timezone=False), onupdate=_get_date))
  </code></pre>
  
  <p>My attempt to add a name to the <code>time_zones</code> table via the flask shell with the <code>TypeError</code>:</p>
  
  <pre><code>&gt;&gt;&gt; from app.main.models import TimeZone
  &gt;&gt;&gt; from app import db
  &gt;&gt;&gt; 
  &gt;&gt;&gt; tz = TimeZone(name='Central Time (US &amp; Canada)')
  Traceback (most recent call last):
    File "&lt;console&gt;", line 1, in &lt;module&gt;
    File "&lt;string&gt;", line 2, in __init__
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/instrumentation.py", line 347, in _new_state_if_none
      state = self._state_constructor(instance, self)
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/util/langhelpers.py", line 747, in __get__
      obj.__dict__[self.__name__] = result = self.fget(obj)
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/instrumentation.py", line 177, in _state_constructor
      self.dispatch.first_init(self, self.class_)
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/event/attr.py", line 256, in __call__
      fn(*args, **kw)
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/mapper.py", line 2860, in _event_on_first_init
      configure_mappers()
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/mapper.py", line 2756, in configure_mappers
      mapper._post_configure_properties()
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/mapper.py", line 1710, in _post_configure_properties
      prop.init()
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/interfaces.py", line 183, in init
      self.do_init()
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/relationships.py", line 1612, in do_init
      self._process_dependent_arguments()
    File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/relationships.py", line 1637, in _process_dependent_arguments
      setattr(self, attr, attr_value())
  TypeError: id() takes exactly one argument (0 given)
  </code></pre>
  
  <h2>UPDATE</h2>
  
  <p>If I remove the relationship from my AppUser class in <code>app.auth.models</code> I do not get this error any more. So I must not have my relationship setup properly.</p>
  
  <p>Here is the <code>models.py</code> im the <code>auth</code> module:</p>
  
  <pre><code>class AppUser(UserMixin, Base):
    __tablename__ = 'app_users'
  
    username = db.Column(db.String(128), nullable=False, unique=True)
    firstname = db.Column(db.String(128))
    lastname = db.Column(db.String(128))
    email = db.Column(db.String(128), nullable=False)
    phone = db.Column(db.VARCHAR(12))
    company = db.Column(db.String(32))
    password_hash = db.Column(db.String(255), nullable=False)
  
    # When I kill these two lines I do not get the error.
    #time_zone_id = db.Column(db.Integer, db.ForeignKey('time_zones.id', ondelete='cascade'))
    #time_zone = db.relationship('TimeZone', backref='app_users', order_by=id)
  
    def __init__(self, username, email, password, firstname, lastname, company, phone):
      self.username = username.lower()
      self.email = email.lower()
      self.firstname = firstname.title()
      self.lastname = lastname.title()
      self.company = company
      self.phone = phone
      #self.time_zone_id = time_zone_id
      self.set_password(password)
  
  
    def set_password(self, password):
      self.password_hash = generate_password_hash(password)
  
    def verify_password(self, password):
      return check_password_hash(self.password_hash, password)
  
    def __repr__(self):
          return '&lt;User %r&gt;' % self.username
  </code></pre>