Domanda

Prima di contrassegnare questo come duplicato:

Ho dato un'occhiata a questo Domanda / risposta , e ho fatto ciò che suggerisce, ma quando aggiungo questo codice:

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())
    )
.

e quindi eseguire alembic upgrade head, ottengo il seguente errore:

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

Quando esamo la tracciata completa dello stack, noto che questo sta causando l'errore:

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

Questa è l'ultima riga del codice sopra ... Come posso risolvere questo?Non ho un indizio che cosa risolverlo ... Aiuto di qualsiasi tipo sarebbe apprezzato.

Ecco i dati che voglio inserire:

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
        },

    ]
)
.

L'errore originale che ottengo quando si tenta di eseguire il bulk_insert è:

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

È stato utile?

Soluzione

Per errore n. 1, non sufficienti informazioni.Hai bisogno di una traccia dello stack.

Per # 2, BULK_INSERT () riceve l'oggetto tabella, non un nome di stringa, come argomento.

Vedi 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)},
    ]
)
.

Altri suggerimenti

Per il primo errore di errore sa.Table e sa.Column con:

from sqlalchemy.sql import table, column

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top