Morgan Allen Morgan Allen - 1 year ago 142
Python Question

AttributeError: "'module' object has no attribute 'ARRAY'"

I'm trying to create a table in SQLAlchemy where the email column is an array of email addresses. However, I'm getting this error:

AttributeError: "'module' object has no attribute 'ARRAY'"

I looked up in the docs

but I guess I didn't understand the correct implementation.

import datetime
from sqlalchemy import schema, types
from sqlalchemy import orm

metadata = schema.MetaData()

def now():

page_table = schema.Table('candidate', metadata,
schema.Column('id', types.Integer, schema.Sequence('page_seq_id', optional=True), primary_key=True),
schema.Column('email', types.ARRAY(String), nullable=False),
schema.Column('first', types.Unicode(255), nullable=False),
schema.Column('last', types.Unicode(255), nullable=False),
schema.Column('company', types.Unicode(255), nullable=False),
schema.Column('title', types.Unicode(255), nullable=False),
schema.Column('linkedin', types.Unicode(255), nullable=False, unique=True),

class Candidate(object):

orm.mapper(Candidate, page_table)

Can any suggest how to make this work?

Answer Source

I'm guessing you want to use this to store multiple emails for a user. Without an ARRAY type, this would traditionally be handled by creating another table -- Email -- with a one-to-many link to the Candidate table.

email_table = schema.Table('email', metadata,
    schema.Column('id', types.Integer, schema.Sequence('email_seq_id', optional=True), primary_key=True),
    schema.Column('email', types.Unicode(255), nullable=False),
    schema.Column('candidate_id', types.Integer, ForeignKey(""), nullable=False),

class Email(object):

mapper(Email, email_table)

mapper(Candidate, page_table, properties={
    'emails' : relationship(Email, backref='candidate',