當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。