sqlalchemy: alembic bulk insert fails: 'str' object has no attribute '_autoincrement_column'

旧城冷巷雨未停 提交于 2019-11-29 09:56:24
daydreamer

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!