summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/mysql.py
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2007-08-12 01:11:44 +0000
committerJason Kirtland <jek@discorporate.us>2007-08-12 01:11:44 +0000
commit138eee02f58cd363716d709e27cedc76df0faf9a (patch)
tree22108659206ce9d83ebb17733894490e43ac48d7 /lib/sqlalchemy/databases/mysql.py
parent2d8b5bb4f36e5624f25b170391fe42d3bfbeb623 (diff)
downloadsqlalchemy-138eee02f58cd363716d709e27cedc76df0faf9a.tar.gz
Allow auto_increment on any pk column, not just the first.
Diffstat (limited to 'lib/sqlalchemy/databases/mysql.py')
-rw-r--r--lib/sqlalchemy/databases/mysql.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index f0b18d3ac..2d9c3af4c 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -1729,13 +1729,16 @@ class MySQLSchemaGenerator(ansisql.ANSISchemaGenerator):
if not column.nullable:
colspec.append('NOT NULL')
- # FIXME: #649 ASAP
- if column.primary_key:
- if (len(column.foreign_keys)==0
- and first_pk
- and column.autoincrement
- and isinstance(column.type, sqltypes.Integer)):
- colspec.append('AUTO_INCREMENT')
+ if column.primary_key and column.autoincrement:
+ try:
+ first = [c for c in column.table.primary_key.columns
+ if (c.autoincrement and
+ isinstance(c.type, sqltypes.Integer) and
+ not c.foreign_keys)].pop(0)
+ if column is first:
+ colspec.append('AUTO_INCREMENT')
+ except IndexError:
+ pass
return ' '.join(colspec)
@@ -1909,6 +1912,8 @@ class MySQLSchemaReflector(object):
# AUTO_INCREMENT
if spec.get('autoincr', False):
col_kw['autoincrement'] = True
+ elif issubclass(col_type, sqltypes.Integer):
+ col_kw['autoincrement'] = False
# DEFAULT
default = spec.get('default', None)