Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

466
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda