0

When making an sqlAlchemy model for an array, give below

class Post(base):
 __tablename__ = "posts"
   answer = column(Array[string],nullable=false)

sqlAlchemy throws fllowing error,

TypeError: Array() missing 1 required positional argument: 'sequence'

what am I doing wrong?

3
  • Array(string)? Where did you import Array from? Commented Jul 4, 2022 at 12:32
  • from sqlalchemy.dialects.postgresql import ARRAY Commented Jul 4, 2022 at 12:39
  • Then it should be Array(String), not [] Commented Jul 4, 2022 at 12:52

1 Answer 1

1

It seems you are not defining the table definition correctly. See the sample table definition.

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import String, Column
from sqlalchemy.dialects.postgresql import ARRAY

Base = declarative_base()

class Post(Base):
    __tablename__ = 'post'

    id = Column(Integer, primary_key=True)
    answer = Column(ARRAY(String))

References:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.