From: Samuel Rayment Date: Wed, 4 Jan 2012 23:15:31 +0000 (+0000) Subject: Column names were not wrapped in quotes when autogenerating a ForeignKeyConstraint. X-Git-Tag: rel_0_1_1~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=350eca2dc8eb6e89645ced3f07ffd0c89f555b7f;p=thirdparty%2Fsqlalchemy%2Falembic.git Column names were not wrapped in quotes when autogenerating a ForeignKeyConstraint. --- diff --git a/alembic/autogenerate.py b/alembic/autogenerate.py index 7e4045b5..193882f6 100644 --- a/alembic/autogenerate.py +++ b/alembic/autogenerate.py @@ -446,7 +446,7 @@ def _render_foreign_key(constraint): # TODO: deferrable, initially, etc. return "%(prefix)sForeignKeyConstraint([%(cols)s], [%(refcols)s], %(args)s)" % { "prefix":_sqlalchemy_autogenerate_prefix(), - "cols":", ".join(f.parent.key for f in constraint.elements), + "cols":", ".join("'%s'" % f.parent.key for f in constraint.elements), "refcols":", ".join(repr(f._get_colspec()) for f in constraint.elements), "args":", ".join( ["%s=%s" % (kwname, val) for kwname, val in opts] diff --git a/tests/test_autogenerate.py b/tests/test_autogenerate.py index 5a84dcd7..0e913cf5 100644 --- a/tests/test_autogenerate.py +++ b/tests/test_autogenerate.py @@ -169,7 +169,7 @@ class AutogenerateDiffTest(TestCase): sa.Column('id', sa.Integer(), nullable=False), sa.Column('description', sa.String(length=100), nullable=True), sa.Column('order_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint([order_id], ['order.order_id'], ), + sa.ForeignKeyConstraint(['order_id'], ['order.order_id'], ), sa.PrimaryKeyConstraint('id') ) op.drop_table('extra') @@ -195,7 +195,7 @@ class AutogenerateDiffTest(TestCase): op.create_table('extra', sa.Column('x', sa.CHAR(), nullable=True), sa.Column('uid', sa.INTEGER(), nullable=True), - sa.ForeignKeyConstraint([uid], ['user.id'], ), + sa.ForeignKeyConstraint(['uid'], ['user.id'], ), sa.PrimaryKeyConstraint() ) op.drop_column('address', 'street') @@ -293,7 +293,7 @@ class AutogenRenderTest(TestCase): "server_default='NOW()', " "nullable=True)," "sa.Column('amount', sa.Numeric(precision=5, scale=2), nullable=True)," - "sa.ForeignKeyConstraint([address_id], ['address.id'], )," + "sa.ForeignKeyConstraint(['address_id'], ['address.id'], )," "sa.PrimaryKeyConstraint('id')" ")" )