Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

453
Views
whenever i try to import models.py in my main.py file it shows me sqlalchemy.exc.ArgumentError
from xmlrpc.client import Boolean
from sqlalchemy import TIMESTAMP, Column, Integer, String
from sqlalchemy.sql.expression import text
from .database import Base

class Post(Base):
    __tablename__ = 'posts'

    id = Column(Integer, primary_key=True, nullable=False)
    title = Column(String, unique=True, nullable=False)
    content = Column(String, nullable=False)
    published = Column(Boolean, server_default='True', nullable=False)
    created_at= Column(TIMESTAMP(timezone=True), nullable= False, server_default=text)

I couldn't find the error. When I try to create the tables using models.Base.metadata.create_all(bind=engine) it gives me the following error:

Traceback (most recent call last):
  File "C:\Users\MINTU\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\sql\schema.py", line 125, in _init_items
    spwd = item._set_parent_with_dispatch
AttributeError: type object 'bool' has no attribute '_set_parent_with_dispatch'

The above exception was the direct cause of the following exception:

File "C:\Users\MINTU\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
    raise exception
sqlalchemy.exc.ArgumentError: 'SchemaItem' object, such as a 'Column' or a 'Constraint' expected, got <class 'bool'>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

First, Boolean must not be imported from xmlrpc.client but from sqlalchemy

Second, the name of your table is not written as tablename but as __tablename__.

Third, text in TIMESTAMP must be called with an argument that I would let you adapt to your needs


from sqlalchemy import TIMESTAMP, Column, Integer, String, Boolean
from sqlalchemy.sql.expression import text
from .database import Base


class Post(Base): 
    __tablename__ = 'posts'

    id = Column(Integer, primary_key=True, nullable=False)
    title = Column(String, unique=True, nullable=False)
    content = Column(String, nullable=False)
    published = Column(Boolean, server_default='True', nullable=False)
    created_at= Column(TIMESTAMP(timezone=True), nullable= False, server_default=text('(now() at time zone "utc")'))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!