- sqlite
- The REFERENCES clause in a CREATE TABLE that includes
- a remote schema name now renders the remote name without
+ a remote schema to another table with the same schema
+ name now renders the remote name without
the schema clause, as required by SQLite. [ticket:1851]
-
+
+ - On the same theme, the REFERENCES clause in a CREATE TABLE
+ that includes a remote schema to a *different* schema
+ than that of the parent table doesn't render at all,
+ as cross-schema references do not appear to be supported.
0.6.5
=====
return super(SQLiteDDLCompiler, self).\
visit_primary_key_constraint(constraint)
-
+
+ def visit_foreign_key_constraint(self, constraint):
+
+ local_table = constraint._elements.values()[0].parent.table
+ remote_table = list(constraint._elements.values())[0].column.table
+
+ if local_table.schema != remote_table.schema:
+ return None
+ else:
+ return super(SQLiteDDLCompiler, self).visit_foreign_key_constraint(constraint)
+
def define_constraint_remote_table(self, constraint, table, preparer):
"""Format the remote table clause of a CREATE CONSTRAINT clause."""
schema='master')
t2 = Table('t2', metadata,
Column('id', Integer, primary_key=True),
- Column('t2_id', Integer, ForeignKey('master.t1.id')),
+ Column('t1_id', Integer, ForeignKey('master.t1.id')),
schema='master'
)
+ t3 = Table('t3', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('t1_id', Integer, ForeignKey('master.t1.id')),
+ schema='alternate'
+ )
+ t4 = Table('t4', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('t1_id', Integer, ForeignKey('master.t1.id')),
+ )
+ # schema->schema, generate REFERENCES with no schema name
self.assert_compile(
schema.CreateTable(t2),
"CREATE TABLE master.t2 ("
"id INTEGER NOT NULL, "
- "t2_id INTEGER, "
+ "t1_id INTEGER, "
"PRIMARY KEY (id), "
- "FOREIGN KEY(t2_id) REFERENCES t1 (id)"
+ "FOREIGN KEY(t1_id) REFERENCES t1 (id)"
+ ")"
+ )
+
+ # schema->different schema, don't generate REFERENCES
+ self.assert_compile(
+ schema.CreateTable(t3),
+ "CREATE TABLE alternate.t3 ("
+ "id INTEGER NOT NULL, "
+ "t1_id INTEGER, "
+ "PRIMARY KEY (id)"
+ ")"
+ )
+
+ # same for local schema
+ self.assert_compile(
+ schema.CreateTable(t4),
+ "CREATE TABLE t4 ("
+ "id INTEGER NOT NULL, "
+ "t1_id INTEGER, "
+ "PRIMARY KEY (id)"
")"
)