本文整理汇总了Python中alembic.op.create_foreign_key方法的典型用法代码示例。如果您正苦于以下问题:Python op.create_foreign_key方法的具体用法?Python op.create_foreign_key怎么用?Python op.create_foreign_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.op
的用法示例。
在下文中一共展示了op.create_foreign_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
conn = op.get_bind()
insp = inspect(conn)
fk_names = [fk['name'] for fk in insp.get_foreign_keys('host')]
if ("fk_hypervisor_id_resource_id" not in fk_names and
"fk_host_id_resource_id" in fk_names):
# NOTE(sileht): we are already good, the BD have been created from
# scratch after "a54c57ada3f5"
return
op.drop_constraint("fk_hypervisor_id_resource_id", "host",
type_="foreignkey")
op.drop_constraint("fk_hypervisor_history_resource_history_revision",
"host_history", type_="foreignkey")
op.create_foreign_key("fk_host_id_resource_id", "host", "resource",
["id"], ["id"], ondelete="CASCADE")
op.create_foreign_key("fk_host_history_resource_history_revision",
"host_history", "resource_history",
["revision"], ["revision"], ondelete="CASCADE")
示例2: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
bind = op.get_bind()
# NOTE(sileht): mysql can't delete an index on a foreign key
# even this one is not the index used by the foreign key itself...
# In our case we have two indexes fk_resource_history_id_resource_id and
# and ix_resource_history_id, we want to delete only the second, but mysql
# can't do that with a simple DROP INDEX ix_resource_history_id...
# so we have to remove the constraint and put it back...
if bind.engine.name == "mysql":
op.drop_constraint("fk_resource_history_id_resource_id",
type_="foreignkey", table_name="resource_history")
for table, colname in resource_tables + history_tables + other_tables:
op.drop_index("ix_%s_%s" % (table, colname), table_name=table)
if bind.engine.name == "mysql":
op.create_foreign_key("fk_resource_history_id_resource_id",
"resource_history", "resource", ["id"], ["id"],
ondelete="CASCADE")
示例3: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('refused_email',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False),
sa.Column('updated_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True),
sa.Column('full_report_path', sa.String(length=128), nullable=False),
sa.Column('path', sa.String(length=128), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('delete_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('full_report_path'),
sa.UniqueConstraint('path')
)
op.add_column('forward_email_log', sa.Column('refused_email_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'forward_email_log', 'refused_email', ['refused_email_id'], ['id'], ondelete='SET NULL')
# ### end Alembic commands ###
示例4: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('mailbox',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False),
sa.Column('updated_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(length=256), nullable=False),
sa.Column('verified', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.add_column('gen_email', sa.Column('mailbox_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'gen_email', 'mailbox', ['mailbox_id'], ['id'], ondelete='cascade')
# ### end Alembic commands ###
示例5: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
op.drop_constraint('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', type_='foreignkey')
op.drop_constraint('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', type_='foreignkey')
op.drop_constraint('pk_kernels', 'kernels', type_='primary')
op.add_column('kernels',
sa.Column('id', GUID(),
server_default=sa.text('uuid_generate_v4()'),
nullable=False))
op.add_column('kernels', sa.Column('role', sa.String(length=16), nullable=False, default='master'))
op.create_primary_key('pk_kernels', 'kernels', ['id'])
op.alter_column(
'kernels', 'sess_id',
existing_type=postgresql.UUID(),
type_=sa.String(length=64),
nullable=True,
existing_server_default=sa.text('uuid_generate_v4()'))
op.create_index(op.f('ix_kernels_sess_id'), 'kernels', ['sess_id'], unique=False)
op.create_index(op.f('ix_kernels_sess_id_role'), 'kernels', ['sess_id', 'role'], unique=False)
op.create_foreign_key('fk_vfolder_attachment_vfolder_vfolders',
'vfolder_attachment', 'vfolders',
['vfolder'], ['id'], onupdate='CASCADE', ondelete='CASCADE')
op.create_foreign_key('fk_vfolder_attachment_kernel_kernels',
'vfolder_attachment', 'kernels',
['kernel'], ['id'], onupdate='CASCADE', ondelete='CASCADE')
示例6: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def downgrade():
op.drop_constraint('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', type_='foreignkey')
op.drop_constraint('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', type_='foreignkey')
op.drop_constraint('pk_kernels', 'kernels', type_='primary')
op.drop_index(op.f('ix_kernels_sess_id'), table_name='kernels')
op.drop_index(op.f('ix_kernels_sess_id_role'), table_name='kernels')
op.alter_column(
'kernels', 'sess_id',
existing_type=sa.String(length=64),
type_=postgresql.UUID(),
nullable=False,
existing_server_default=sa.text('uuid_generate_v4()'),
postgresql_using='sess_id::uuid')
op.create_primary_key('pk_kernels', 'kernels', ['sess_id'])
op.drop_column('kernels', 'id')
op.drop_column('kernels', 'role')
op.create_foreign_key('fk_vfolder_attachment_vfolder_vfolders',
'vfolder_attachment', 'vfolders',
['vfolder'], ['id'])
op.create_foreign_key('fk_vfolder_attachment_kernel_kernels',
'vfolder_attachment', 'kernels',
['kernel'], ['sess_id'])
示例7: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
""" Alter the pull_requests table to update the foreign key to set null
on delete.
"""
op.drop_constraint(
'pull_requests_project_id_from_fkey',
'pull_requests',
type_='foreignkey')
op.create_foreign_key(
name='pull_requests_project_id_from_fkey',
source_table='pull_requests',
referent_table='projects',
local_cols=['project_id_from'],
remote_cols=['id'],
onupdate='cascade',
ondelete='set null',
)
示例8: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def downgrade():
""" Alter the pull_requests table to update the foreign key to cascade
on delete.
"""
op.drop_constraint(
'pull_requests_project_id_from_fkey',
'pull_requests',
type_='foreignkey')
op.create_foreign_key(
name='pull_requests_project_id_from_fkey',
source_table='pull_requests',
referent_table='projects',
local_cols=['project_id_from'],
remote_cols=['id'],
onupdate='cascade',
ondelete='cascade',
)
示例9: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
""" Remove the existing foreign key in pull_request_flags.token_id and
re-create it with CASCADE on delete and update.
"""
# alter the constraints
op.drop_constraint(
'pull_request_flags_token_id_fkey', 'pull_request_flags',
type_='foreignkey')
op.create_foreign_key(
u'pull_request_flags_token_id_fkey',
'pull_request_flags',
'tokens',
['token_id'],
['id'],
ondelete="CASCADE",
onupdate="CASCADE",
)
示例10: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('rss_parser_feed_name_lut', sa.Column('feed_id', sa.BigInteger(), nullable=False))
op.create_index(op.f('ix_rss_parser_feed_name_lut_feed_id'), 'rss_parser_feed_name_lut', ['feed_id'], unique=False)
op.drop_index('ix_rss_parser_feed_name_lut_feed_name', table_name='rss_parser_feed_name_lut')
op.drop_constraint('rss_parser_feed_name_lut_feed_netloc_feed_name_key', 'rss_parser_feed_name_lut', type_='unique')
op.create_unique_constraint(None, 'rss_parser_feed_name_lut', ['feed_netloc', 'feed_id'])
op.drop_constraint('rss_parser_feed_name_lut_feed_name_fkey', 'rss_parser_feed_name_lut', type_='foreignkey')
op.create_foreign_key(None, 'rss_parser_feed_name_lut', 'rss_parser_funcs', ['feed_id'], ['id'])
op.drop_column('rss_parser_feed_name_lut', 'feed_name')
op.add_column('rss_parser_feed_name_lut_version', sa.Column('feed_id', sa.BigInteger(), autoincrement=False, nullable=True))
op.create_index(op.f('ix_rss_parser_feed_name_lut_version_feed_id'), 'rss_parser_feed_name_lut_version', ['feed_id'], unique=False)
op.drop_index('ix_rss_parser_feed_name_lut_version_feed_name', table_name='rss_parser_feed_name_lut_version')
op.drop_column('rss_parser_feed_name_lut_version', 'feed_name')
op.alter_column('rss_parser_funcs', 'func',
existing_type=sa.TEXT(),
nullable=True)
### end Alembic commands ###
示例11: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.alter_column('rss_parser_funcs', 'func',
existing_type=sa.TEXT(),
nullable=False)
op.add_column('rss_parser_feed_name_lut_version', sa.Column('feed_name', sa.TEXT(), autoincrement=False, nullable=True))
op.create_index('ix_rss_parser_feed_name_lut_version_feed_name', 'rss_parser_feed_name_lut_version', ['feed_name'], unique=False)
op.drop_index(op.f('ix_rss_parser_feed_name_lut_version_feed_id'), table_name='rss_parser_feed_name_lut_version')
op.drop_column('rss_parser_feed_name_lut_version', 'feed_id')
op.add_column('rss_parser_feed_name_lut', sa.Column('feed_name', sa.TEXT(), autoincrement=False, nullable=False))
op.drop_constraint(None, 'rss_parser_feed_name_lut', type_='foreignkey')
op.create_foreign_key('rss_parser_feed_name_lut_feed_name_fkey', 'rss_parser_feed_name_lut', 'rss_parser_funcs', ['feed_name'], ['feed_name'])
op.drop_constraint(None, 'rss_parser_feed_name_lut', type_='unique')
op.create_unique_constraint('rss_parser_feed_name_lut_feed_netloc_feed_name_key', 'rss_parser_feed_name_lut', ['feed_netloc', 'feed_name'])
op.create_index('ix_rss_parser_feed_name_lut_feed_name', 'rss_parser_feed_name_lut', ['feed_name'], unique=False)
op.drop_index(op.f('ix_rss_parser_feed_name_lut_feed_id'), table_name='rss_parser_feed_name_lut')
op.drop_column('rss_parser_feed_name_lut', 'feed_id')
### end Alembic commands ###
示例12: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('bank_account', sa.Column('kyc_application_id', sa.Integer(), nullable=True))
op.add_column('bank_account', sa.Column('wyre_id', sa.String(), nullable=True))
op.drop_constraint('bank_account_business_verification_id_fkey', 'bank_account', type_='foreignkey')
op.create_foreign_key(None, 'bank_account', 'kyc_application', ['kyc_application_id'], ['id'])
op.drop_column('bank_account', 'business_verification_id')
op.drop_column('blockchain_transaction', 'has_output_txn')
op.drop_column('blockchain_transaction', 'is_bitcoin')
op.drop_column('credit_transfer', 'uuid')
op.add_column('kyc_application', sa.Column('type', sa.String(), nullable=True))
op.drop_constraint('transfer_card_user_id_fkey', 'transfer_card', type_='foreignkey')
op.drop_column('transfer_card', '_amount_loaded')
op.drop_column('transfer_card', 'user_id')
op.drop_column('transfer_card', 'amount_loaded_signature')
op.add_column('uploaded_document', sa.Column('kyc_application_id', sa.Integer(), nullable=True))
op.drop_constraint('uploaded_document_business_verification_id_fkey', 'uploaded_document', type_='foreignkey')
op.create_foreign_key(None, 'uploaded_document', 'kyc_application', ['kyc_application_id'], ['id'])
op.drop_column('uploaded_document', 'business_verification_id')
op.add_column('user', sa.Column('public_serial_number', sa.String(), nullable=True))
op.drop_column('user', '_public_serial_number')
# ### end Alembic commands ###
示例13: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user', sa.Column('_public_serial_number', sa.VARCHAR(), autoincrement=False, nullable=True))
op.drop_column('user', 'public_serial_number')
op.add_column('uploaded_document', sa.Column('business_verification_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.drop_constraint(None, 'uploaded_document', type_='foreignkey')
op.create_foreign_key('uploaded_document_business_verification_id_fkey', 'uploaded_document', 'kyc_application', ['business_verification_id'], ['id'])
op.drop_column('uploaded_document', 'kyc_application_id')
op.add_column('transfer_card', sa.Column('amount_loaded_signature', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('transfer_card', sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.add_column('transfer_card', sa.Column('_amount_loaded', sa.INTEGER(), autoincrement=False, nullable=True))
op.create_foreign_key('transfer_card_user_id_fkey', 'transfer_card', 'user', ['user_id'], ['id'])
op.drop_column('kyc_application', 'type')
op.add_column('credit_transfer', sa.Column('uuid', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('blockchain_transaction', sa.Column('is_bitcoin', sa.BOOLEAN(), autoincrement=False, nullable=True))
op.add_column('blockchain_transaction', sa.Column('has_output_txn', sa.BOOLEAN(), autoincrement=False, nullable=True))
op.add_column('bank_account', sa.Column('business_verification_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.drop_constraint(None, 'bank_account', type_='foreignkey')
op.create_foreign_key('bank_account_business_verification_id_fkey', 'bank_account', 'kyc_application', ['business_verification_id'], ['id'])
op.drop_column('bank_account', 'wyre_id')
op.drop_column('bank_account', 'kyc_application_id')
# ### end Alembic commands ###
示例14: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('user', 'last_name')
op.drop_column('user', 'first_name')
op.add_column('transfer_account', sa.Column('vendor_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.add_column('transfer_account', sa.Column('first_name', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('transfer_account', sa.Column('last_name', sa.VARCHAR(), autoincrement=False, nullable=True))
op.create_foreign_key('transfer_account_vendor_id_fkey', 'transfer_account', 'transfer_account', ['vendor_id'], ['id'])
op.drop_column('transfer_account', 'payable_period_type')
op.drop_column('transfer_account', 'payable_period_length')
op.drop_column('transfer_account', 'payable_epoch')
op.drop_column('transfer_account', 'name')
op.drop_column('transfer_account', 'is_vendor')
op.create_table('vendor',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('payable_period_type', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('payable_period_length', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='vendor_pkey')
)
# ### end Alembic commands ###
示例15: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_foreign_key [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('targeting_survey',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created', sa.DateTime(), nullable=True),
sa.Column('number_people_household', sa.Integer(), nullable=True),
sa.Column('number_below_adult_age_household', sa.Integer(), nullable=True),
sa.Column('number_people_women_household', sa.Integer(), nullable=True),
sa.Column('number_people_men_household', sa.Integer(), nullable=True),
sa.Column('number_people_work_household', sa.Integer(), nullable=True),
sa.Column('disabilities_household', sa.String(), nullable=True),
sa.Column('long_term_illnesses_household', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.add_column('feedback', sa.Column('question', sa.String(), nullable=True))
op.add_column('user', sa.Column('targeting_survey_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'user', 'targeting_survey', ['targeting_survey_id'], ['id'])
# ### end Alembic commands ###