Pregunta

Antes de marcar esto como un duplicado:

Eché un vistazo a este Pregunta / respuesta , y hice lo que sugiere, pero cuando agrego este código:

permslookup = sa.Table('permslookup',
    sa.Column('perms_lookup_id', primary_key=True),
    sa.Column('name', sa.Unicode(40), index=True),
    sa.Column('description', sa.Text),
    sa.Column('value', sa.Numeric(10, 2)),
    sa.Column('ttype', sa.PickleType(), index=True),
    sa.Column('permission', sa.Unicode(40), index=True),
    sa.Column('options', sa.PickleType())
    )

y luego ejecute alembic upgrade head, obtengo el siguiente error:

AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema'

Cuando examino la traza de pila completa, noté que esto está causando el error:

sa.Column('options', sa.PickleType())

Esta es la última línea del código anterior ... ¿Cómo puedo resolver esto?No tengo ni idea de cómo resolverlo ... La ayuda de cualquier tipo sería apreciada.

Aquí están los datos que quiero insertar:

op.bulk_insert('permslookup',
    [
        {
            'id': 1,
            'name': 'accounts',
            'description': """ Have permission to do all transactions """,
            'value': 1,
            'ttype': ['cash', 'loan', 'mgmt', 'deposit', 'adjustments'],
            'permission': 'accounts',
            'options': None
        },
        {
            'id': 2,
            'name': 'agent_manage',
            'description': """ Have permission to do cash, cash, loan and Management Discretion transactions """,
            'value': 2,
            'ttype': ['cash', 'loan', 'mgmt'],
            'permission': 'agent_manage',
            'options': None
        },
        {
            'id': 3,
            'name': 'corrections',
            'description': """ Have permission to do cash, loan and adjustments transactions """,
            'value': 3,
            'ttype': ['cash', 'loan', 'adjustments'],
            'permission': 'corrections',
            'options': None
        },
        {
            'id': 4,
            'name': 'cashup',
            'description': """ Have permission to do cash and loan transactions """,
            'value': 4,
            'ttype': ['cash', 'loan'],
            'permission': 'cashup',
            'options': None
        },

    ]
)

El error original que recibo al intentar ejecutar el código bulk_insert es:

AttributeError: 'str' object has no attribute '_autoincrement_column'

¿Fue útil?

Solución

por error # 1, no hay suficiente información.Necesita un rastro de pila.

para # 2, bulk_insert () recibe el objeto de tabla, no un nombre de cadena, como argumento.

Consulte http://alembic.readthedocs.org/en/latest/ops.html#alembic.Operations.Operations.bulk_insert :

from alembic import op
from datetime import date
from sqlalchemy.sql import table, column
from sqlalchemy import String, Integer, Date

# Create an ad-hoc table to use for the insert statement.
accounts_table = table('account',
    column('id', Integer),
    column('name', String),
    column('create_date', Date)
)

op.bulk_insert(accounts_table,
    [
        {'id':1, 'name':'John Smith',
                'create_date':date(2010, 10, 5)},
        {'id':2, 'name':'Ed Williams',
                'create_date':date(2007, 5, 27)},
        {'id':3, 'name':'Wendy Jones',
                'create_date':date(2008, 8, 15)},
    ]
)

Otros consejos

para el primer interruptor de error sa.Table y sa.Column con:

from sqlalchemy.sql import table, column

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top