title: Sqlalchemy - core - creating copy of an existing table
body: <p>I need to create a table based on an existing table in the same (Oracle) schema. I don't want to have any constraint on the new table, even if original table may have one or more.</p>
  
  <p>I have tried to create new table from the original table by using <code>column.copy()</code>, but for some reason, I am not able to drop the constraints after creating the new table in database.</p>
  
  <pre><code>def clone_table_approach_1(original_table, connection, metadata):
      try:
          new_table_name = original_table.name + '_sync'
          columns = [c.copy() for c in original_table.columns]
          new_table = Table(new_table_name, metadata, quote=False, *columns)
  
          # Create table in database
          if not new_table.exists():
              new_table.create()
          else:
              raise Exception("New table already exists")
  
          # Remove constraints from new table if any
          for constraint in new_table.constraints:
              connection.execute(DropConstraint(constraint))
  
          # Return table handle for newly created table
          final_cloned_table = Table(new_table, metadata, quote=False)
          return final_cloned_table
  
      except:
          # Drop if we did create a new table
          if new_table.exists():
              new_table.drop()
          raise
  </code></pre>
  
  <p>This fails while dropping the constraints. It seems sqlalchemy is not aware of names of the constraints created on new table in the database. I can see the new table with constraint names like "SYS_C00450822" and "SYS_C00450823" (these are NOT NULL check constraints).</p>
  
  <p>Exception:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/gaurav/myprojects/python/sync/test_table_copy.py", line 163, in &lt;module&gt;
      t_product_new = clone_table_approach_1(t_product, target_conn, target_metadata)
    File "/home/gaurav/myprojects/python/sync/test_table_copy.py", line 57, in clone_table_approach_1
      connection.execute(DropConstraint(constraint))
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 729, in execute
      return meth(self, multiparams, params)
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/ddl.py", line 69, in _execute_on_connection
      return connection._execute_ddl(self, multiparams, params)
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 777, in _execute_ddl
      compiled = ddl.compile(dialect=dialect)
    File "&lt;string&gt;", line 1, in &lt;lambda&gt;
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/elements.py", line 493, in compile
      return self._compiler(dialect, bind=bind, **kw)
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/ddl.py", line 27, in _compiler
      return dialect.ddl_compiler(dialect, self, **kw)
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/compiler.py", line 199, in __init__
      self.string = self.process(self.statement, **compile_kwargs)
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/compiler.py", line 222, in process
      return obj._compiler_dispatch(self, **kwargs)
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/visitors.py", line 80, in _compiler_dispatch
      return meth(self, **kw)
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/compiler.py", line 2518, in visit_drop_constraint
      self.preparer.format_constraint(drop.element),
    File "&lt;string&gt;", line 1, in &lt;lambda&gt;
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/compiler.py", line 2928, in format_constraint
      return self.quote(constraint.name)
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/compiler.py", line 2893, in quote
      if self._requires_quotes(ident):
    File "/home/gaurav/.local/lib/python3.4/site-packages/sqlalchemy/sql/compiler.py", line 2864, in _requires_quotes
      lc_value = value.lower()
  AttributeError: 'NoneType' object has no attribute 'lower'
  </code></pre>
  
  <p>Is there any other better approach to this?</p>