Sqlalchemy: Alembic Bulk Insert Fails: 'str' Object Has No Attribute '_autoincrement_column'
My model looks like class Category(UserMixin, db.Model): __tablename__ = 'categories' uuid = Column('uuid', GUID(), default=uuid.uuid4, primary_key=True,
Solution 1:
all I had to do is to create a table
before bulk_insert, even if I have a explicit schema in separate models.py
import sqlalchemy as sa
from sqlalchemy.sql import table
from alembic import op
def upgrade():
categories = table('categories',
sa.Column('uuid', UUID(),
primary_key=True,
unique=True, autoincrement=False),
sa.Column('name', String),
sa.Column('parent', String),
sa.Column('created_on', sa.types.DateTime(timezone=True),
default=datetime.utcnow())
)
op.bulk_insert(categories,
[
{'name': 'first', 'parent': 'first_parent'},
{'name': 'second', 'parent': 'second_parent'}
]
)
and then I was able to to run alembic upgrade head
without any issues and data was serialized successfully in database.
Post a Comment for "Sqlalchemy: Alembic Bulk Insert Fails: 'str' Object Has No Attribute '_autoincrement_column'"