summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-02-22 19:28:25 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-02-22 19:28:25 +0000
commit4460f998e3b856e94e870c08cb4ed357027ced00 (patch)
tree14277a86c0607003e07a1a176e9163afaa860262 /lib/sqlalchemy/sql
parent055ac80eb2ca7676e78d9c8e49c7fe96a74e802c (diff)
downloadsqlalchemy-4460f998e3b856e94e870c08cb4ed357027ced00.tar.gz
- Composite PK table on InnoDB where the "autoincrement" column
isn't first will emit an explicit "KEY" phrase within CREATE TABLE thereby avoiding errors, [ticket:1496]
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 187b4d26f..32aa2a992 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -1004,17 +1004,26 @@ class DDLCompiler(engine.Compiled):
if const:
text += " " + const
+ const = self.create_table_constraints(table)
+ if const:
+ text += ", \n\t" + const
+
+ text += "\n)%s\n\n" % self.post_create_table(table)
+ return text
+
+ def create_table_constraints(self, table):
+
# On some DB order is significant: visit PK first, then the
# other constraints (engine.ReflectionTest.testbasic failed on FB2)
+ constraints = []
if table.primary_key:
- pk = self.process(table.primary_key)
- if pk:
- text += ", \n\t" + pk
+ constraints.append(table.primary_key)
+
+ constraints.extend([c for c in table.constraints if c is not table.primary_key])
- const = ", \n\t".join(p for p in
- (self.process(constraint) for constraint in table.constraints
- if constraint is not table.primary_key
- and (
+ return ", \n\t".join(p for p in
+ (self.process(constraint) for constraint in constraints
+ if (
constraint._create_rule is None or
constraint._create_rule(self))
and (
@@ -1022,11 +1031,6 @@ class DDLCompiler(engine.Compiled):
not getattr(constraint, 'use_alter', False)
)) if p is not None
)
- if const:
- text += ", \n\t" + const
-
- text += "\n)%s\n\n" % self.post_create_table(table)
- return text
def visit_drop_table(self, drop):
ret = "\nDROP TABLE " + self.preparer.format_table(drop.element)