diff options
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index c6c30629d..5ecec7d6c 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -3022,6 +3022,10 @@ class DDLCompiler(Compiled): text = "CREATE " if index.unique: text += "UNIQUE " + if index.name is None: + raise exc.CompileError( + "CREATE INDEX requires that the index have a name" + ) text += "INDEX %s ON %s (%s)" % ( self._prepared_index_name(index, include_schema=include_schema), preparer.format_table( @@ -3038,6 +3042,11 @@ class DDLCompiler(Compiled): def visit_drop_index(self, drop): index = drop.element + + if index.name is None: + raise exc.CompileError( + "DROP INDEX requires that the index have a name" + ) return "\nDROP INDEX " + self._prepared_index_name( index, include_schema=True ) @@ -3251,7 +3260,8 @@ class DDLCompiler(Compiled): text = "" if constraint.name is not None: formatted_name = self.preparer.format_constraint(constraint) - text += "CONSTRAINT %s " % formatted_name + if formatted_name is not None: + text += "CONSTRAINT %s " % formatted_name text += "UNIQUE (%s)" % ( ", ".join(self.preparer.quote(c.name) for c in constraint) ) |