config option is being used but SQL access isn't
desired.
+- [bug] Repaired create_foreign_key() for
+ self-referential foreign keys, which weren't working
+ at all.
+
- [bug] 'alembic' command reports an informative
error message when the configuration is missing
the 'script_directory' key. #63
local_cols, remote_cols,
onupdate=None, ondelete=None):
m = schema.MetaData()
- t1 = schema.Table(source, m,
- *[schema.Column(n, NULLTYPE) for n in local_cols])
- t2 = schema.Table(referent, m,
+ if source == referent:
+ t1_cols = local_cols + remote_cols
+ else:
+ t1_cols = local_cols
+ schema.Table(referent, m,
*[schema.Column(n, NULLTYPE) for n in remote_cols])
+ t1 = schema.Table(source, m,
+ *[schema.Column(n, NULLTYPE) for n in t1_cols])
+
f = schema.ForeignKeyConstraint(local_cols,
["%s.%s" % (referent, n)
for n in remote_cols],
"REFERENCES t2 (bat, hoho) ON DELETE CASCADE"
)
+def test_add_foreign_key_self_referential():
+ context = op_fixture()
+ op.create_foreign_key("fk_test", "t1", "t1", ["foo"], ["bar"])
+ context.assert_(
+ "ALTER TABLE t1 ADD CONSTRAINT fk_test "
+ "FOREIGN KEY(foo) REFERENCES t1 (bar)"
+ )
+
def test_add_check_constraint():
context = op_fixture()
op.create_check_constraint(