Reputation: 1535
Before you flag this as a duplicate:
I did take a look at this question/answer, and I did do what it suggests, but when I do add this code:
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())
)
and then run alembic upgrade head
, I get the following error:
AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema'
When I examine the full stack trace, I notice that This is causing the error:
sa.Column('options', sa.PickleType())
This is the last line of the above code... How can I resolve this? I have not a clue what how to solve it... Help of any kind would be appreciated.
Here is the data I want to insert:
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
},
]
)
The original error I get when trying to run the bulk_insert
is:
AttributeError: 'str' object has no attribute '_autoincrement_column'
Upvotes: 5
Views: 5006
Reputation: 889
For first error switch sa.Table
and sa.Column
with:
from sqlalchemy.sql import table, column
Upvotes: 0
Reputation: 75117
For error #1, not enough information. Need a stack trace.
For #2, bulk_insert() receives the Table object, not a string name, as the argument.
see 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)},
]
)
Upvotes: 10