当前位置: 首页>>代码示例>>Python>>正文


Python sqlalchemy.ForeignKey方法代码示例

本文整理汇总了Python中sqlalchemy.ForeignKey方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.ForeignKey方法的具体用法?Python sqlalchemy.ForeignKey怎么用?Python sqlalchemy.ForeignKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy的用法示例。


在下文中一共展示了sqlalchemy.ForeignKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def upgrade():
    op.create_table(
        'error_logs',
        IDColumn(),
        sa.Column('created_at', sa.DateTime(timezone=True),
                  server_default=sa.func.now(), index=True),
        sa.Column('severity', sa.Enum('critical', 'error', 'warning', 'info', 'debug', name='errorlog_severity'),
                  index=True),
        sa.Column('source', sa.String),
        sa.Column('user', GUID, sa.ForeignKey('users.uuid'), nullable=True, index=True),
        sa.Column('is_read', sa.Boolean, default=False, index=True),
        sa.Column('is_cleared', sa.Boolean, default=False, index=True),
        sa.Column('message', sa.Text),
        sa.Column('context_lang', sa.String),
        sa.Column('context_env', postgresql.JSONB()),
        sa.Column('request_url', sa.String, nullable=True),
        sa.Column('request_status', sa.Integer, nullable=True),
        sa.Column('traceback', sa.Text, nullable=True),
    ) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:21,代码来源:d2aafa234374_create_error_logs_table.py

示例2: revision

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def revision(cls):
        tablename_compact = cls.__tablename__
        if tablename_compact.endswith("_history"):
            tablename_compact = tablename_compact[:-6]
        return sqlalchemy.Column(
            sqlalchemy.Integer,
            sqlalchemy.ForeignKey(
                'resource_history.revision',
                ondelete="CASCADE",
                name="fk_%s_revision_rh_revision"
                % tablename_compact,
                # NOTE(sileht): We use to ensure that postgresql
                # does not use AccessExclusiveLock on destination table
                use_alter=True),
            primary_key=True
        ) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:18,代码来源:sqlalchemy_base.py

示例3: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def upgrade():
    op.create_table(
        'session_templates',
        IDColumn('id'),
        sa.Column('created_at', sa.DateTime(timezone=True),
                  server_default=sa.func.now(), index=True),
        sa.Column('is_active', sa.Boolean, default=True),
        sa.Column('type',
                  sa.Enum('TASK', 'CLUSTER', name='templatetypes'),
                  nullable=False,
                  server_default='TASK'
                  ),
        sa.Column('domain_name', sa.String(length=64), sa.ForeignKey('domains.name'), nullable=False),
        sa.Column('group_id', GUID, sa.ForeignKey('groups.id'), nullable=True),
        sa.Column('user_uuid', GUID, sa.ForeignKey('users.uuid'), nullable=False),

        sa.Column('name', sa.String(length=128), nullable=True),
        sa.Column('template', sa.String(length=16 * 1024), nullable=False)
    )
    op.add_column(
        'kernels',
        sa.Column('bootstrap_script', sa.String(length=4 * 1024), nullable=True)
    ) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:25,代码来源:ce209920f654_create_task_template_table.py

示例4: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def upgrade():
    ''' Create the pr_to_issue table. '''

    op.create_table(
        'pr_to_issue',
        sa.Column(
            'pull_request_uid',
            sa.String(32),
            sa.ForeignKey(
                'pull_requests.uid', ondelete='CASCADE', onupdate='CASCADE',
            ),
            primary_key=True),
        sa.Column(
            'issue_uid',
            sa.String(32),
            sa.ForeignKey(
                'issues.uid', ondelete='CASCADE', onupdate='CASCADE',
            ),
            primary_key=True)
    ) 
开发者ID:Pagure,项目名称:pagure,代码行数:22,代码来源:369deb8c8b63_add_the_pr_to_issue_table.py

示例5: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def upgrade():
    ''' Add the columns editor_id and edited_on to the table issue_comments.
    '''

    op.add_column(
        'issue_comments',
        sa.Column(
            'editor_id',
            sa.Integer,
            sa.ForeignKey('users.id', onupdate='CASCADE'),
            nullable=True)
    )

    op.add_column(
        'issue_comments',
        sa.Column(
            'edited_on',
            sa.DateTime,
            nullable=True)
    ) 
开发者ID:Pagure,项目名称:pagure,代码行数:22,代码来源:3b441ef4e928_comment_editing_issue.py

示例6: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def upgrade():
    """ Create the tags_pull_requests to store the tags of pull-requests.
    """
    op.create_table(
        'tags_pull_requests',
        sa.Column(
            'tag_id',
            sa.Integer,
            sa.ForeignKey(
                'tags_colored.id', ondelete='CASCADE', onupdate='CASCADE',
            ),
            primary_key=True),
        sa.Column(
            'request_uid',
            sa.String(32),
            sa.ForeignKey(
                'pull_requests.uid', ondelete='CASCADE', onupdate='CASCADE',
            ),
            primary_key=True),
        sa.Column(
            'date_created',
            sa.DateTime,
            nullable=False,
            default=datetime.datetime.utcnow),
    ) 
开发者ID:Pagure,项目名称:pagure,代码行数:27,代码来源:a13967424130_add_pr_tags_table.py

示例7: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def upgrade():
    ''' Add the columns editor_id and edited_on to the table
    pull_request_comments.
    '''

    op.add_column(
        'pull_request_comments',
        sa.Column(
            'editor_id',
            sa.Integer,
            sa.ForeignKey('users.id', onupdate='CASCADE'),
            nullable=True)
    )

    op.add_column(
        'pull_request_comments',
        sa.Column(
            'edited_on',
            sa.DateTime,
            nullable=True)
    ) 
开发者ID:Pagure,项目名称:pagure,代码行数:23,代码来源:15ea3c2cf83d_pr_comment_editing.py

示例8: __iter__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def __iter__(self):
        for column in self.reflected_parent_columns:
            yield column

        # Only yield internal version columns if parent model is not using
        # single table inheritance
        if not self.model or not sa.inspect(self.model).single:

            yield self.transaction_column
            if self.option('strategy') == 'validity':
                yield self.end_transaction_column
            yield self.operation_type_column

            yield sa.Column(
                "data_hash",
                UUID,
                index=True,
                unique=True
            )
            yield sa.Column(
                "parent_hash",
                UUID,
                sa.ForeignKey("{}.data_hash".format(self.table_name)),
                index=True
            ) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:27,代码来源:table_builder.py

示例9: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def upgrade():
    op.add_column(
        u'amphora',
        sa.Column(u'load_balancer_id', sa.String(36),
                  sa.ForeignKey(u'load_balancer.id',
                                name=u'fk_amphora_load_balancer_id'),
                  nullable=True)
    )
    op.drop_table(u'load_balancer_amphora')
    op.drop_constraint(
        u'fk_container_provisioning_status_name', u'amphora',
        type_=u'foreignkey'
    )
    op.create_foreign_key(
        u'fk_amphora_provisioning_status_name', u'amphora',
        u'provisioning_status', [u'status'], [u'name']
    ) 
开发者ID:openstack,项目名称:octavia,代码行数:19,代码来源:4c094013699a_update_load_balancer_amphora.py

示例10: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def upgrade():
    op.create_table(
        "a10_scaling_group_member_virtual_server_ports",
        sa.Column('id',
                  sa.String(36),
                  primary_key=True,
                  nullable=False),
        sa.Column('created_at', sa.DateTime, nullable=False),
        sa.Column('updated_at', sa.DateTime, nullable=False),
        sa.Column('virtual_server_id',
                  sa.String(36),
                  sa.ForeignKey(u'a10_scaling_group_member_virtual_servers.id'),
                  nullable=False),
        sa.Column('port',
                  sa.Integer,
                  nullable=False),
        sa.Column('protocol',
                  sa.String(255),
                  nullable=False),
        sa.Column('sflow_uuid',
                  sa.String(36),
                  nullable=False),
    ) 
开发者ID:a10networks,项目名称:a10-neutron-lbaas,代码行数:25,代码来源:152ed5d509bc_scaling_group_member_virtual_server_1f.py

示例11: create_followers_to_followings_table

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def create_followers_to_followings_table() -> None:
    op.create_table(
        "followers_to_followings",
        sa.Column(
            "follower_id",
            sa.Integer,
            sa.ForeignKey("users.id", ondelete="CASCADE"),
            nullable=False,
        ),
        sa.Column(
            "following_id",
            sa.Integer,
            sa.ForeignKey("users.id", ondelete="CASCADE"),
            nullable=False,
        ),
    )
    op.create_primary_key(
        "pk_followers_to_followings",
        "followers_to_followings",
        ["follower_id", "following_id"],
    ) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:23,代码来源:fdf8821871d7_main_tables.py

示例12: create_articles_table

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def create_articles_table() -> None:
    op.create_table(
        "articles",
        sa.Column("id", sa.Integer, primary_key=True),
        sa.Column("slug", sa.Text, unique=True, nullable=False, index=True),
        sa.Column("title", sa.Text, nullable=False),
        sa.Column("description", sa.Text, nullable=False),
        sa.Column("body", sa.Text, nullable=False),
        sa.Column(
            "author_id", sa.Integer, sa.ForeignKey("users.id", ondelete="SET NULL")
        ),
        *timestamps(),
    )
    op.execute(
        """
        CREATE TRIGGER update_article_modtime
            BEFORE UPDATE
            ON articles
            FOR EACH ROW
        EXECUTE PROCEDURE update_updated_at_column();
        """
    ) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:24,代码来源:fdf8821871d7_main_tables.py

示例13: create_articles_to_tags_table

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def create_articles_to_tags_table() -> None:
    op.create_table(
        "articles_to_tags",
        sa.Column(
            "article_id",
            sa.Integer,
            sa.ForeignKey("articles.id", ondelete="CASCADE"),
            nullable=False,
        ),
        sa.Column(
            "tag",
            sa.Text,
            sa.ForeignKey("tags.tag", ondelete="CASCADE"),
            nullable=False,
        ),
    )
    op.create_primary_key(
        "pk_articles_to_tags", "articles_to_tags", ["article_id", "tag"]
    ) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:21,代码来源:fdf8821871d7_main_tables.py

示例14: create_favorites_table

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def create_favorites_table() -> None:
    op.create_table(
        "favorites",
        sa.Column(
            "user_id",
            sa.Integer,
            sa.ForeignKey("users.id", ondelete="CASCADE"),
            nullable=False,
        ),
        sa.Column(
            "article_id",
            sa.Integer,
            sa.ForeignKey("articles.id", ondelete="CASCADE"),
            nullable=False,
        ),
    )
    op.create_primary_key("pk_favorites", "favorites", ["user_id", "article_id"]) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:19,代码来源:fdf8821871d7_main_tables.py

示例15: test_foreign_key_options

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ForeignKey [as 别名]
def test_foreign_key_options(metadata):
    Table(
        "simple_items",
        metadata,
        Column(
            "name", VARCHAR, ForeignKey("simple_items.name", ondelete="CASCADE", onupdate="CASCADE", deferrable=True, initially="DEFERRED")
        ),
    )

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, MetaData, String, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('name', String, ForeignKey('simple_items.name', ondelete='CASCADE', \
onupdate='CASCADE', deferrable=True, initially='DEFERRED'))
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:27,代码来源:test_codegen.py


注:本文中的sqlalchemy.ForeignKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。