我使用alembic来管理我的数据库结构。alembic并获取最后插入的值
在使用id作为Integer和主键添加表后,id列将成为自动增量列。我如何查询升级脚本中的数据,所以我确定我得到了正确的ID(我知道在这种情况下它是1)?
我知道我如何
#creating the table
op.create_table(
'srv_feed_return_type',
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('name', sa.String(50), nullable=False),
sa.Column('created', sa.DateTime, server_default=func.now(), nullable=False),
sa.Column('created_by', sa.String(50), nullable=False),
sa.Column('last_updated', sa.DateTime, nullable=False),
sa.Column('last_updated_by', sa.String(50), nullable=False)
)
#table for operations
srv_feed_return_type = table('srv_feed_return_type',
column('name'),
column('created'),
column('created_by'),
column('last_updated'),
column('last_updated_by'))
#bulk insert
op.bulk_insert(srv_feed_return_type,
[
{'name': 'dataset',
'created': datetime.now(), 'created_by': 'Asken',
'last_updated': datetime.now(), 'last_updated_by': 'Asken'}
])
知道我可以做更新,但我怎么做一个选择使用类似的东西象下面这样?
op.execute(
srv_feed_return_type.update().\
where(srv_feed_return_type.c.name==op.inline_literal('dataset')).\
values({'name':op.inline_literal('somethingelse')})
)
它是安全的假设,直到迁移完成后不会有任何其他进程修改您的新创建的表? – vvladymyrov 2013-03-21 13:59:23
这个例子是的,但我知道它会在这里。在另一次迁移中,它不会再是1了。我需要知道特定返回类型的ID。 – Asken 2013-03-21 14:11:07
你的应用程序使用了哪些数据库,是否有可能让更多的数据库到另一个数据库 - 是否需要让应用程序成为数据库不可知的? – vvladymyrov 2013-03-21 15:24:32