문제

이것을 중복으로 표시하기 전에:

나 이거 좀 봤는데 질문 답변, 제안된 대로 수행했지만 실제로 다음 코드를 추가하면 다음과 같습니다.

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

그런 다음 실행 alembic upgrade head, 다음 오류가 발생합니다.

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

전체 스택 추적을 조사해 보면 이로 인해 오류가 발생하는 것으로 나타났습니다.

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

위 코드의 마지막 줄입니다.이 문제를 어떻게 해결할 수 있나요?어떻게 해결해야 할지 감이 안잡히네요...어떤 종류의 도움이라도 주시면 감사하겠습니다.

삽입하려는 데이터는 다음과 같습니다.

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

    ]
)

실행하려고 할 때 발생하는 원래 오류 bulk_insert 이다:

AttributeError: 'str' object has no attribute '_autoincrement_column'
도움이 되었습니까?

해결책

오류 # 1의 경우 정보가 충분하지 않습니다.스택 추적이 필요합니다.

# 2에 대해, bulk_insert ()는 문자열 이름이 아닌 테이블 개체를 인수로받습니다.

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

다른 팁

첫 번째 오류 스위치의 경우 sa.Table 그리고 sa.Column 와 함께:

from sqlalchemy.sql import table, column

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top