python-3.xsqlalchemycratedb

Compiler state error when inserting data to CrateDb


I am trying to connect to the crateDB and insert data. Although the DB migrations work perfectly - it shows the following error when am trying to insert data

TypeError: _get_crud_params() missing 1 required positional argument: 'compile_state'

Following is my code:

engine = create_engine('crate://localhost:4200', echo=False)

class Devices(Base):
    __tablename__ = 'registereddevices'
    id = Column('id',Integer, primary_key=True)
    bunkId = Column('bunkId', String)
    deviceType = Column('deviceType', String)
    deviceName = Column('deviceName', String)

Base.metadata.create_all(bind=engine)
Session = sessionmaker(bind=engine)
session = Session()

try:
    device = Devices()
    device.id = 1
    device.bunkId = "sads"
    device.deviceType = "fdsfd"
    device.deviceName = "gdf"

    session.add(device)
    session.commit()
except exc.SQLAlchemyError as e:
    print(type(e))

Solution

  • are you using SQLAlchemy 1.4? As per the footnote on the Dialects page, crate-python is currently only compatible with SQLAlchemy 1.3.

    If you need to stick to 1.4, you might also try using a regular PostgreSQL driver, as CrateDB's SQL dialect is widely compatible with PostgreSQL.