Here are the examples of the python api sqlalchemy.ForeignKeyConstraint taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
43 Examples
3
View Complete Implementation : field.py
Copyright Mozilla Public License 2.0
Author : AnyBlok
Copyright Mozilla Public License 2.0
Author : AnyBlok
@clastmethod
def define_table_args(cls):
table_args = super(Field, cls).define_table_args()
if cls.__registry_name__ != System.Field.__registry_name__:
F = cls.registry.System.Field
return table_args + (ForeignKeyConstraint([cls.name, cls.model],
[F.name, F.model],
ondelete="CASCADE"),)
return table_args
3
View Complete Implementation : relationship.py
Copyright Mozilla Public License 2.0
Author : AnyBlok
Copyright Mozilla Public License 2.0
Author : AnyBlok
def update_table_args(self, registry, Model):
"""Add foreign key constraint in table args"""
return [
ForeignKeyConstraint(self.col_names, self.fk_names,
**self.foreign_key_options)
]
3
View Complete Implementation : models.py
Copyright GNU General Public License v3.0
Author : nyaadevs
Copyright GNU General Public License v3.0
Author : nyaadevs
@declarative.declared_attr
def __table_args__(cls):
return (
Index(cls._table_prefix('uploader_flag_idx'), 'uploader_id', 'flags'),
ForeignKeyConstraint(
['main_category_id', 'sub_category_id'],
[cls._table_prefix('sub_categories.main_category_id'),
cls._table_prefix('sub_categories.id')]
), {}
)
3
View Complete Implementation : DapModelClasses.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : sdss
Copyright BSD 3-Clause "New" or "Revised" License
Author : sdss
def ClastFactory(name, tableName, BaseClast=db.Base, fks=None):
tableArgs = [{'autoload': True, 'schema': 'mangadapdb'}]
if fks:
for fk in fks:
tableArgs.insert(0, ForeignKeyConstraint([fk[0]], [fk[1]]))
newclast = type(
name, (BaseClast,),
{'__tablename__': tableName,
'__table_args__': tuple(tableArgs)})
return newclast
3
View Complete Implementation : SampleModelClasses.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : sdss
Copyright BSD 3-Clause "New" or "Revised" License
Author : sdss
def ClastFactory(name, tableName, BaseClast=db.Base, fks=None):
tableArgs = [{'autoload': True, 'schema': 'mangasampledb'}]
if fks:
for fk in fks:
tableArgs.insert(0, ForeignKeyConstraint([fk[0]], [fk[1]]))
newclast = type(
name, (BaseClast,),
{'__tablename__': tableName,
'__table_args__': tuple(tableArgs)})
return newclast
3
View Complete Implementation : test_autogen_diffs.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def setUp(self):
self.metadata = m = MetaData()
t = Table(
"t",
m,
Column("id", Integer(), primary_key=True),
Column("x", Integer()),
)
self.ix = Index("ix1", t.c.id)
fk = ForeignKeyConstraint(["t_id"], ["t.id"])
q = Table("q", m, Column("t_id", Integer()), fk)
self.table = t
self.fk = fk
self.ck = CheckConstraint(t.c.x > 5)
t.append_constraint(self.ck)
self.uq = UniqueConstraint(q.c.t_id)
self.pk = t.primary_key
3
View Complete Implementation : test_reflection.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_oracle_has_no_on_update_cascade(self):
bar = Table(
"bar",
self.metadata,
Column("id", Integer, primary_key=True),
Column(
"foo_id", Integer, ForeignKey("foo.id", onupdate="CASCADE")
),
)
astert_raises(exc.SAWarning, bar.create)
bat = Table(
"bat",
self.metadata,
Column("id", Integer, primary_key=True),
Column("foo_id", Integer),
ForeignKeyConstraint(["foo_id"], ["foo.id"], onupdate="CASCADE"),
)
astert_raises(exc.SAWarning, bat.create)
3
View Complete Implementation : test_constraints.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_render_add_fk_constraint_stringcol(self):
t, t2 = self._constraint_create_fixture()
constraint = ForeignKeyConstraint(["b"], ["t2.a"])
t.append_constraint(constraint)
self.astert_compile(
schema.AddConstraint(constraint),
"ALTER TABLE tbl ADD FOREIGN KEY(b) REFERENCES t2 (a)",
)
3
View Complete Implementation : test_constraints.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_render_add_fk_constraint_realcol(self):
t, t2 = self._constraint_create_fixture()
constraint = ForeignKeyConstraint([t.c.a], [t2.c.b])
t.append_constraint(constraint)
self.astert_compile(
schema.AddConstraint(constraint),
"ALTER TABLE tbl ADD FOREIGN KEY(a) REFERENCES t2 (b)",
)
0
View Complete Implementation : util.py
Copyright MIT License
Author : analyzeDFIR
Copyright MIT License
Author : analyzeDFIR
def drop_all_tables(engine, inspector, schema=None, include_names=None):
from sqlalchemy import Column, Table, Integer, MetaData, \
ForeignKeyConstraint
from sqlalchemy.schema import DropTable, DropConstraint
if include_names is not None:
include_names = set(include_names)
with engine.connect() as conn:
for tname, fkcs in reversed(
inspector.get_sorted_table_and_fkc_names(schema=schema)):
if tname:
if include_names is not None and tname not in include_names:
continue
conn.execute(DropTable(
Table(tname, MetaData(), schema=schema)
))
elif fkcs:
if not engine.dialect.supports_alter:
continue
for tname, fkc in fkcs:
if include_names is not None and \
tname not in include_names:
continue
tb = Table(
tname, MetaData(),
Column('x', Integer),
Column('y', Integer),
schema=schema
)
conn.execute(DropConstraint(
ForeignKeyConstraint(
[tb.c.x], [tb.c.y], name=fkc)
))