%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python37/share/doc/alt-python37-alembic/docs/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python37/share/doc/alt-python37-alembic/docs/ops.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Operation Reference &mdash; Alembic 0.8.3 documentation</title>
    
    <link rel="stylesheet" href="_static/nature_override.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/changelog.css" type="text/css" />
    <link rel="stylesheet" href="_static/sphinx_paramlinks.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.8.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="Alembic 0.8.3 documentation" href="index.html" />
    <link rel="next" title="Cookbook" href="cookbook.html" />
    <link rel="prev" title="Working with Branches" href="branches.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="cookbook.html" title="Cookbook"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="branches.html" title="Working with Branches"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Alembic 0.8.3 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="operation-reference">
<span id="ops"></span><h1>Operation Reference<a class="headerlink" href="#operation-reference" title="Permalink to this headline">¶</a></h1>
<p>This file provides documentation on Alembic migration directives.</p>
<p>The directives here are used within user-defined migration files,
within the <code class="docutils literal"><span class="pre">upgrade()</span></code> and <code class="docutils literal"><span class="pre">downgrade()</span></code> functions, as well as
any functions further invoked by those.</p>
<p>All directives exist as methods on a class called <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a>.
When migration scripts are run, this object is made available
to the script via the <code class="docutils literal"><span class="pre">alembic.op</span></code> datamember, which is
a <em>proxy</em> to an actual instance of <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a>.
Currently, <code class="docutils literal"><span class="pre">alembic.op</span></code> is a real Python module, populated
with individual proxies for each method on <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a>,
so symbols can be imported safely from the <code class="docutils literal"><span class="pre">alembic.op</span></code> namespace.</p>
<p>The <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> system is also fully extensible.  See
<a class="reference internal" href="api/operations.html#operation-plugins"><span>Operation Plugins</span></a> for details on this.</p>
<p>A key design philosophy to the <a class="reference internal" href="api/operations.html#alembic-operations-toplevel"><span>Operation Directives</span></a> methods is that
to the greatest degree possible, they internally generate the
appropriate SQLAlchemy metadata, typically involving
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> and <a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#sqlalchemy.schema.Constraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Constraint</span></code></a>
objects.  This so that migration instructions can be
given in terms of just the string names and/or flags involved.
The exceptions to this
rule include the <a class="reference internal" href="#alembic.operations.Operations.add_column" title="alembic.operations.Operations.add_column"><code class="xref py py-meth docutils literal"><span class="pre">add_column()</span></code></a> and <a class="reference internal" href="#alembic.operations.Operations.create_table" title="alembic.operations.Operations.create_table"><code class="xref py py-meth docutils literal"><span class="pre">create_table()</span></code></a>
directives, which require full <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Column" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Column</span></code></a>
objects, though the table metadata is still generated here.</p>
<p>The functions here all require that a <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a> has been
configured within the <code class="docutils literal"><span class="pre">env.py</span></code> script first, which is typically
via <a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure" title="alembic.runtime.environment.EnvironmentContext.configure"><code class="xref py py-meth docutils literal"><span class="pre">EnvironmentContext.configure()</span></code></a>.   Under normal
circumstances they are called from an actual migration script, which
itself would be invoked by the <a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.run_migrations" title="alembic.runtime.environment.EnvironmentContext.run_migrations"><code class="xref py py-meth docutils literal"><span class="pre">EnvironmentContext.run_migrations()</span></code></a>
method.</p>
<span class="target" id="module-alembic.operations"></span><dl class="class">
<dt id="alembic.operations.Operations">
<em class="property">class </em><code class="descclassname">alembic.operations.</code><code class="descname">Operations</code><span class="sig-paren">(</span><em>migration_context</em>, <em>impl=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations" title="Permalink to this definition">¶</a></dt>
<dd><p>Define high level migration operations.</p>
<p>Each operation corresponds to some schema migration operation,
executed against a particular <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a>
which in turn represents connectivity to a database,
or a file output stream.</p>
<p>While <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> is normally configured as
part of the <a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.run_migrations" title="alembic.runtime.environment.EnvironmentContext.run_migrations"><code class="xref py py-meth docutils literal"><span class="pre">EnvironmentContext.run_migrations()</span></code></a>
method called from an <code class="docutils literal"><span class="pre">env.py</span></code> script, a standalone
<a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> instance can be
made for use cases external to regular Alembic
migrations by passing in a <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic.migration</span> <span class="kn">import</span> <span class="n">MigrationContext</span>
<span class="kn">from</span> <span class="nn">alembic.operations</span> <span class="kn">import</span> <span class="n">Operations</span>

<span class="n">conn</span> <span class="o">=</span> <span class="n">myengine</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">MigrationContext</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">conn</span><span class="p">)</span>
<span class="n">op</span> <span class="o">=</span> <span class="n">Operations</span><span class="p">(</span><span class="n">ctx</span><span class="p">)</span>

<span class="n">op</span><span class="o">.</span><span class="n">alter_column</span><span class="p">(</span><span class="s">&quot;t&quot;</span><span class="p">,</span> <span class="s">&quot;c&quot;</span><span class="p">,</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that as of 0.8, most of the methods on this class are produced
dynamically using the <a class="reference internal" href="#alembic.operations.Operations.register_operation" title="alembic.operations.Operations.register_operation"><code class="xref py py-meth docutils literal"><span class="pre">Operations.register_operation()</span></code></a>
method.</p>
<p>Construct a new <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.Operations.params.migration_context"></span><strong>migration_context</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.params.migration_context">¶</a> &#8211; a <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a>
instance.</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="alembic.operations.Operations.add_column">
<code class="descname">add_column</code><span class="sig-paren">(</span><em>table_name</em>, <em>column</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.add_column" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue an &#8220;add column&#8221; instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">String</span>

<span class="n">op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="s">&#39;organization&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">())</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The provided <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Column" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Column</span></code></a> object can also
specify a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#sqlalchemy.schema.ForeignKey" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></code></a>, referencing
a remote table name.  Alembic will automatically generate a stub
&#8220;referenced&#8221; table and emit a second ALTER statement in order
to add the constraint separately:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">ForeignKey</span>

<span class="n">op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="s">&#39;organization&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;account_id&#39;</span><span class="p">,</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;accounts.id&#39;</span><span class="p">))</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Note that this statement uses the <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Column" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Column</span></code></a>
construct as is from the SQLAlchemy library.  In particular,
default values to be created on the database side are
specified using the <code class="docutils literal"><span class="pre">server_default</span></code> parameter, and not
<code class="docutils literal"><span class="pre">default</span></code> which only specifies Python-side defaults:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">func</span>

<span class="c"># specify &quot;DEFAULT NOW&quot; along with the column add</span>
<span class="n">op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="s">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;timestamp&#39;</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">func</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.add_column.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.add_column.params.table_name">¶</a> &#8211; String name of the parent table.</li>
<li><span class="target" id="alembic.operations.Operations.add_column.params.column"></span><strong>column</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.add_column.params.column">¶</a> &#8211; a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Column" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Column</span></code></a> object
representing the new column.</li>
<li><span class="target" id="alembic.operations.Operations.add_column.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.add_column.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.alter_column">
<code class="descname">alter_column</code><span class="sig-paren">(</span><em>table_name</em>, <em>column_name</em>, <em>nullable=None</em>, <em>server_default=False</em>, <em>new_column_name=None</em>, <em>type_=None</em>, <em>existing_type=None</em>, <em>existing_server_default=False</em>, <em>existing_nullable=None</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.alter_column" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue an &#8220;alter column&#8221; instruction using the
current migration context.</p>
<p>Generally, only that aspect of the column which
is being changed, i.e. name, type, nullability,
default, needs to be specified.  Multiple changes
can also be specified at once and the backend should
&#8220;do the right thing&#8221;, emitting each change either
separately or together as the backend allows.</p>
<p>MySQL has special requirements here, since MySQL
cannot ALTER a column without a full specification.
When producing MySQL-compatible migration files,
it is recommended that the <code class="docutils literal"><span class="pre">existing_type</span></code>,
<code class="docutils literal"><span class="pre">existing_server_default</span></code>, and <code class="docutils literal"><span class="pre">existing_nullable</span></code>
parameters be present, if not being altered.</p>
<p>Type changes which are against the SQLAlchemy
&#8220;schema&#8221; types <a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_basics.html#sqlalchemy.types.Boolean" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Boolean</span></code></a>
and  <a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_basics.html#sqlalchemy.types.Enum" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Enum</span></code></a> may also
add or drop constraints which accompany those
types on backends that don&#8217;t support them natively.
The <code class="docutils literal"><span class="pre">existing_server_default</span></code> argument is
used in this case as well to remove a previous
constraint.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.alter_column.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.table_name">¶</a> &#8211; string name of the target table.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.column_name"></span><strong>column_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.column_name">¶</a> &#8211; string name of the target column,
as it exists before the operation begins.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.nullable"></span><strong>nullable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.nullable">¶</a> &#8211; Optional; specify <code class="docutils literal"><span class="pre">True</span></code> or <code class="docutils literal"><span class="pre">False</span></code>
to alter the column&#8217;s nullability.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.server_default"></span><strong>server_default</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.server_default">¶</a> &#8211; Optional; specify a string
SQL expression, <a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.expression.text" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">text()</span></code></a>,
or <a class="reference external" href="http://www.sqlalchemy.org/docs/core/defaults.html#sqlalchemy.schema.DefaultClause" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">DefaultClause</span></code></a> to indicate
an alteration to the column&#8217;s default value.
Set to <code class="docutils literal"><span class="pre">None</span></code> to have the default removed.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.new_column_name"></span><strong>new_column_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.new_column_name">¶</a> &#8211; Optional; specify a string name here to
indicate the new name within a column rename operation.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.type_"></span><strong>type_</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.type_">¶</a> &#8211; Optional; a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_api.html#sqlalchemy.types.TypeEngine" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">TypeEngine</span></code></a>
type object to specify a change to the column&#8217;s type.
For SQLAlchemy types that also indicate a constraint (i.e.
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_basics.html#sqlalchemy.types.Boolean" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Boolean</span></code></a>, <a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_basics.html#sqlalchemy.types.Enum" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Enum</span></code></a>),
the constraint is also generated.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.autoincrement"></span><strong>autoincrement</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.autoincrement">¶</a> &#8211; set the <code class="docutils literal"><span class="pre">AUTO_INCREMENT</span></code> flag of the column;
currently understood by the MySQL dialect.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.existing_type"></span><strong>existing_type</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.existing_type">¶</a> &#8211; Optional; a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_api.html#sqlalchemy.types.TypeEngine" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">TypeEngine</span></code></a>
type object to specify the previous type.   This
is required for all MySQL column alter operations that
don&#8217;t otherwise specify a new type, as well as for
when nullability is being changed on a SQL Server
column.  It is also used if the type is a so-called
SQLlchemy &#8220;schema&#8221; type which may define a constraint (i.e.
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_basics.html#sqlalchemy.types.Boolean" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Boolean</span></code></a>,
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_basics.html#sqlalchemy.types.Enum" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Enum</span></code></a>),
so that the constraint can be dropped.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.existing_server_default"></span><strong>existing_server_default</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.existing_server_default">¶</a> &#8211; Optional; The existing
default value of the column.   Required on MySQL if
an existing default is not being changed; else MySQL
removes the default.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.existing_nullable"></span><strong>existing_nullable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.existing_nullable">¶</a> &#8211; Optional; the existing nullability
of the column.  Required on MySQL if the existing nullability
is not being changed; else MySQL sets this to NULL.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.existing_autoincrement"></span><strong>existing_autoincrement</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.existing_autoincrement">¶</a> &#8211; Optional; the existing autoincrement
of the column.  Used for MySQL&#8217;s system of altering a column
that specifies <code class="docutils literal"><span class="pre">AUTO_INCREMENT</span></code>.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.batch_alter_table">
<code class="descname">batch_alter_table</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwds</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.batch_alter_table" title="Permalink to this definition">¶</a></dt>
<dd><p>Invoke a series of per-table migrations in batch.</p>
<p>Batch mode allows a series of operations specific to a table
to be syntactically grouped together, and allows for alternate
modes of table migration, in particular the &#8220;recreate&#8221; style of
migration required by SQLite.</p>
<p>&#8220;recreate&#8221; style is as follows:</p>
<ol class="arabic simple">
<li>A new table is created with the new specification, based on the
migration directives within the batch, using a temporary name.</li>
<li>the data copied from the existing table to the new table.</li>
<li>the existing table is dropped.</li>
<li>the new table is renamed to the existing table name.</li>
</ol>
<p>The directive by default will only use &#8220;recreate&#8221; style on the
SQLite backend, and only if directives are present which require
this form, e.g. anything other than <code class="docutils literal"><span class="pre">add_column()</span></code>.   The batch
operation on other backends will proceed using standard ALTER TABLE
operations.</p>
<p>The method is used as a context manager, which returns an instance
of <a class="reference internal" href="#alembic.operations.BatchOperations" title="alembic.operations.BatchOperations"><code class="xref py py-class docutils literal"><span class="pre">BatchOperations</span></code></a>; this object is the same as
<a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> except that table names and schema names
are omitted.  E.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">with</span> <span class="n">op</span><span class="o">.</span><span class="n">batch_alter_table</span><span class="p">(</span><span class="s">&quot;some_table&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">batch_op</span><span class="p">:</span>
    <span class="n">batch_op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="n">Column</span><span class="p">(</span><span class="s">&#39;foo&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">))</span>
    <span class="n">batch_op</span><span class="o">.</span><span class="n">drop_column</span><span class="p">(</span><span class="s">&#39;bar&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The operations within the context manager are invoked at once
when the context is ended.   When run against SQLite, if the
migrations include operations not supported by SQLite&#8217;s ALTER TABLE,
the entire table will be copied to a new one with the new
specification, moving all data across as well.</p>
<p>The copy operation by default uses reflection to retrieve the current
structure of the table, and therefore <a class="reference internal" href="#alembic.operations.Operations.batch_alter_table" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-meth docutils literal"><span class="pre">batch_alter_table()</span></code></a>
in this mode requires that the migration is run in &#8220;online&#8221; mode.
The <code class="docutils literal"><span class="pre">copy_from</span></code> parameter may be passed which refers to an existing
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code> object, which will bypass this reflection step.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The table copy operation will currently not copy
CHECK constraints, and may not copy UNIQUE constraints that are
unnamed, as is possible on SQLite.   See the section
<a class="reference internal" href="batch.html#sqlite-batch-constraints"><span>Dealing with Constraints</span></a> for workarounds.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.table_name">¶</a> &#8211; name of table</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.schema">¶</a> &#8211; optional schema name.</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.recreate"></span><strong>recreate</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.recreate">¶</a> &#8211; under what circumstances the table should be
recreated. At its default of <code class="docutils literal"><span class="pre">&quot;auto&quot;</span></code>, the SQLite dialect will
recreate the table if any operations other than <code class="docutils literal"><span class="pre">add_column()</span></code>,
<code class="docutils literal"><span class="pre">create_index()</span></code>, or <code class="docutils literal"><span class="pre">drop_index()</span></code> are
present. Other options include <code class="docutils literal"><span class="pre">&quot;always&quot;</span></code> and <code class="docutils literal"><span class="pre">&quot;never&quot;</span></code>.</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.copy_from"></span><strong>copy_from</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.copy_from">¶</a> &#8211; <p>optional <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> object
that will act as the structure of the table being copied.  If omitted,
table reflection is used to retrieve the structure of the table.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.6: </span>Fully implemented the
<a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.copy_from" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">copy_from</span></code></a>
parameter.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="batch.html#batch-offline-mode"><span>Working in Offline Mode</span></a></p>
<p><a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.reflect_args" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">reflect_args</span></code></a></p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.reflect_kwargs" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">reflect_kwargs</span></code></a></p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.reflect_args"></span><strong>reflect_args</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.reflect_args">¶</a> &#8211; <p>a sequence of additional positional arguments that
will be applied to the table structure being reflected / copied;
this may be used to pass column and constraint overrides to the
table that will be reflected, in lieu of passing the whole
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> using
<a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.copy_from" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">copy_from</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.1.</span></p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.reflect_kwargs"></span><strong>reflect_kwargs</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.reflect_kwargs">¶</a> &#8211; <p>a dictionary of additional keyword arguments
that will be applied to the table structure being copied; this may be
used to pass additional table and reflection options to the table that
will be reflected, in lieu of passing the whole
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> using
<a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.copy_from" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">copy_from</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.1.</span></p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.table_args"></span><strong>table_args</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.table_args">¶</a> &#8211; a sequence of additional positional arguments that
will be applied to the new <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> when
created, in addition to those copied from the source table.
This may be used to provide additional constraints such as CHECK
constraints that may not be reflected.</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.table_kwargs"></span><strong>table_kwargs</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.table_kwargs">¶</a> &#8211; a dictionary of additional keyword arguments
that will be applied to the new <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a>
when created, in addition to those copied from the source table.
This may be used to provide for additional table options that may
not be reflected.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0.</span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.Operations.batch_alter_table.params.naming_convention"></span><strong>naming_convention</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.naming_convention">¶</a> &#8211; <p>a naming convention dictionary of the form
described at <a class="reference internal" href="naming.html#autogen-naming-conventions"><span>Integration of Naming Conventions into Operations, Autogenerate</span></a> which will be applied
to the <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.MetaData" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">MetaData</span></code></a> during the reflection
process.  This is typically required if one wants to drop SQLite
constraints, as these constraints will not have names when
reflected on this backend.  Requires SQLAlchemy <strong>0.9.4</strong> or greater.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="batch.html#dropping-sqlite-foreign-keys"><span>Dropping Unnamed or Named Foreign Key Constraints</span></a></p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.1.</span></p>
</div>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">batch mode requires SQLAlchemy 0.8 or above.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="batch.html#batch-migrations"><span>Running &#8220;Batch&#8221; Migrations for SQLite and Other Databases</span></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.bulk_insert">
<code class="descname">bulk_insert</code><span class="sig-paren">(</span><em>table</em>, <em>rows</em>, <em>multiinsert=True</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.bulk_insert" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;bulk insert&#8221; operation using the current
migration context.</p>
<p>This provides a means of representing an INSERT of multiple rows
which works equally well in the context of executing on a live
connection as well as that of generating a SQL script.   In the
case of a SQL script, the values are rendered inline into the
statement.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">date</span>
<span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">table</span><span class="p">,</span> <span class="n">column</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">String</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">Date</span>

<span class="c"># Create an ad-hoc table to use for the insert statement.</span>
<span class="n">accounts_table</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">column</span><span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
    <span class="n">column</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
    <span class="n">column</span><span class="p">(</span><span class="s">&#39;create_date&#39;</span><span class="p">,</span> <span class="n">Date</span><span class="p">)</span>
<span class="p">)</span>

<span class="n">op</span><span class="o">.</span><span class="n">bulk_insert</span><span class="p">(</span><span class="n">accounts_table</span><span class="p">,</span>
    <span class="p">[</span>
        <span class="p">{</span><span class="s">&#39;id&#39;</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span> <span class="s">&#39;name&#39;</span><span class="p">:</span><span class="s">&#39;John Smith&#39;</span><span class="p">,</span>
                <span class="s">&#39;create_date&#39;</span><span class="p">:</span><span class="n">date</span><span class="p">(</span><span class="mi">2010</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">)},</span>
        <span class="p">{</span><span class="s">&#39;id&#39;</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="s">&#39;name&#39;</span><span class="p">:</span><span class="s">&#39;Ed Williams&#39;</span><span class="p">,</span>
                <span class="s">&#39;create_date&#39;</span><span class="p">:</span><span class="n">date</span><span class="p">(</span><span class="mi">2007</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">27</span><span class="p">)},</span>
        <span class="p">{</span><span class="s">&#39;id&#39;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span> <span class="s">&#39;name&#39;</span><span class="p">:</span><span class="s">&#39;Wendy Jones&#39;</span><span class="p">,</span>
                <span class="s">&#39;create_date&#39;</span><span class="p">:</span><span class="n">date</span><span class="p">(</span><span class="mi">2008</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">15</span><span class="p">)},</span>
    <span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<p>When using &#8211;sql mode, some datatypes may not render inline
automatically, such as dates and other special types.   When this
issue is present, <a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">Operations.inline_literal()</span></code></a> may be used:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">op</span><span class="o">.</span><span class="n">bulk_insert</span><span class="p">(</span><span class="n">accounts_table</span><span class="p">,</span>
    <span class="p">[</span>
        <span class="p">{</span><span class="s">&#39;id&#39;</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span> <span class="s">&#39;name&#39;</span><span class="p">:</span><span class="s">&#39;John Smith&#39;</span><span class="p">,</span>
                <span class="s">&#39;create_date&#39;</span><span class="p">:</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s">&quot;2010-10-05&quot;</span><span class="p">)},</span>
        <span class="p">{</span><span class="s">&#39;id&#39;</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="s">&#39;name&#39;</span><span class="p">:</span><span class="s">&#39;Ed Williams&#39;</span><span class="p">,</span>
                <span class="s">&#39;create_date&#39;</span><span class="p">:</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s">&quot;2007-05-27&quot;</span><span class="p">)},</span>
        <span class="p">{</span><span class="s">&#39;id&#39;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span> <span class="s">&#39;name&#39;</span><span class="p">:</span><span class="s">&#39;Wendy Jones&#39;</span><span class="p">,</span>
                <span class="s">&#39;create_date&#39;</span><span class="p">:</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s">&quot;2008-08-15&quot;</span><span class="p">)},</span>
    <span class="p">],</span>
    <span class="n">multiinsert</span><span class="o">=</span><span class="bp">False</span>
<span class="p">)</span>
</pre></div>
</div>
<p>When using <a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">Operations.inline_literal()</span></code></a> in conjunction with
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-meth docutils literal"><span class="pre">Operations.bulk_insert()</span></code></a>, in order for the statement to work
in &#8220;online&#8221; (e.g. non &#8211;sql) mode, the
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert.params.multiinsert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-paramref docutils literal"><span class="pre">multiinsert</span></code></a>
flag should be set to <code class="docutils literal"><span class="pre">False</span></code>, which will have the effect of
individual INSERT statements being emitted to the database, each
with a distinct VALUES clause, so that the &#8220;inline&#8221; values can
still be rendered, rather than attempting to pass the values
as bound parameters.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.4: </span><a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">Operations.inline_literal()</span></code></a> can now
be used with <a class="reference internal" href="#alembic.operations.Operations.bulk_insert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-meth docutils literal"><span class="pre">Operations.bulk_insert()</span></code></a>, and the
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert.params.multiinsert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-paramref docutils literal"><span class="pre">multiinsert</span></code></a> flag has
been added to assist in this usage when running in &#8220;online&#8221;
mode.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.bulk_insert.params.table"></span><strong>table</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.bulk_insert.params.table">¶</a> &#8211; a table object which represents the target of the INSERT.</li>
<li><span class="target" id="alembic.operations.Operations.bulk_insert.params.rows"></span><strong>rows</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.bulk_insert.params.rows">¶</a> &#8211; a list of dictionaries indicating rows.</li>
<li><span class="target" id="alembic.operations.Operations.bulk_insert.params.multiinsert"></span><strong>multiinsert</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.bulk_insert.params.multiinsert">¶</a> &#8211; <p>when at its default of True and &#8211;sql mode is not
enabled, the INSERT statement will be executed using
&#8220;executemany()&#8221; style, where all elements in the list of
dictionaries are passed as bound parameters in a single
list.   Setting this to False results in individual INSERT
statements being emitted per parameter set, and is needed
in those cases where non-literal values are present in the
parameter sets.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.4.</span></p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_check_constraint">
<code class="descname">create_check_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>condition</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_check_constraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create check constraint&#8221; instruction using the
current migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">column</span><span class="p">,</span> <span class="n">func</span>

<span class="n">op</span><span class="o">.</span><span class="n">create_check_constraint</span><span class="p">(</span>
    <span class="s">&quot;ck_user_name_len&quot;</span><span class="p">,</span>
    <span class="s">&quot;user&quot;</span><span class="p">,</span>
    <span class="n">func</span><span class="o">.</span><span class="n">len</span><span class="p">(</span><span class="n">column</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">))</span> <span class="o">&gt;</span> <span class="mi">5</span>
<span class="p">)</span>
</pre></div>
</div>
<p>CHECK constraints are usually against a SQL expression, so ad-hoc
table metadata is usually needed.   The function will convert the given
arguments into a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#sqlalchemy.schema.CheckConstraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.CheckConstraint</span></code></a> bound
to an anonymous table in order to emit the CREATE statement.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.name">¶</a> &#8211; Name of the check constraint.  The name is necessary
so that an ALTER statement can be emitted.  For setups that
use an automated naming scheme such as that described at
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#constraint-naming-conventions" title="(in SQLAlchemy v1.0)"><span>Configuring Constraint Naming Conventions</span></a>,
<code class="docutils literal"><span class="pre">name</span></code> here can be <code class="docutils literal"><span class="pre">None</span></code>, as the event listener will
apply the name to the constraint object when it is associated
with the table.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.table_name">¶</a> &#8211; String name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.condition"></span><strong>condition</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.condition">¶</a> &#8211; SQL expression that&#8217;s the condition of the
constraint. Can be a string or SQLAlchemy expression language
structure.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.deferrable">¶</a> &#8211; optional bool. If set, emit DEFERRABLE or
NOT DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.initially">¶</a> &#8211; optional string. If set, emit INITIALLY &lt;value&gt;
when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>source -&gt; table_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_foreign_key">
<code class="descname">create_foreign_key</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>source_table</em>, <em>referent_table</em>, <em>local_cols</em>, <em>remote_cols</em>, <em>onupdate=None</em>, <em>ondelete=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>match=None</em>, <em>source_schema=None</em>, <em>referent_schema=None</em>, <em>**dialect_kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_foreign_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create foreign key&#8221; instruction using the
current migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_foreign_key</span><span class="p">(</span>
            <span class="s">&quot;fk_user_address&quot;</span><span class="p">,</span> <span class="s">&quot;address&quot;</span><span class="p">,</span>
            <span class="s">&quot;user&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s">&quot;user_id&quot;</span><span class="p">],</span> <span class="p">[</span><span class="s">&quot;id&quot;</span><span class="p">])</span>
</pre></div>
</div>
<p>This internally generates a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> object
containing the necessary columns, then generates a new
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#sqlalchemy.schema.ForeignKeyConstraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></code></a>
object which it then associates with the
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a>.
Any event listeners associated with this action will be fired
off normally.   The <a class="reference external" href="http://www.sqlalchemy.org/docs/core/ddl.html#sqlalchemy.schema.AddConstraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">AddConstraint</span></code></a>
construct is ultimately used to generate the ALTER statement.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.name">¶</a> &#8211; Name of the foreign key constraint.  The name is necessary
so that an ALTER statement can be emitted.  For setups that
use an automated naming scheme such as that described at
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#constraint-naming-conventions" title="(in SQLAlchemy v1.0)"><span>Configuring Constraint Naming Conventions</span></a>,
<code class="docutils literal"><span class="pre">name</span></code> here can be <code class="docutils literal"><span class="pre">None</span></code>, as the event listener will
apply the name to the constraint object when it is associated
with the table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.source_table"></span><strong>source_table</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.source_table">¶</a> &#8211; String name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.referent_table"></span><strong>referent_table</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.referent_table">¶</a> &#8211; String name of the destination table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.local_cols"></span><strong>local_cols</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.local_cols">¶</a> &#8211; a list of string column names in the
source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.remote_cols"></span><strong>remote_cols</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.remote_cols">¶</a> &#8211; a list of string column names in the
remote table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.onupdate"></span><strong>onupdate</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.onupdate">¶</a> &#8211; Optional string. If set, emit ON UPDATE &lt;value&gt; when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.ondelete"></span><strong>ondelete</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.ondelete">¶</a> &#8211; Optional string. If set, emit ON DELETE &lt;value&gt; when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.deferrable">¶</a> &#8211; optional bool. If set, emit DEFERRABLE or NOT
DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.source_schema"></span><strong>source_schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.source_schema">¶</a> &#8211; Optional schema name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.referent_schema"></span><strong>referent_schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.referent_schema">¶</a> &#8211; Optional schema name of the destination table.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>source -&gt; source_table</li>
<li>referent -&gt; referent_table</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_index">
<code class="descname">create_index</code><span class="sig-paren">(</span><em>index_name</em>, <em>table_name</em>, <em>columns</em>, <em>schema=None</em>, <em>unique=False</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create index&#8221; instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="s">&#39;ik_test&#39;</span><span class="p">,</span> <span class="s">&#39;t1&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;foo&#39;</span><span class="p">,</span> <span class="s">&#39;bar&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>Functional indexes can be produced by using the
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.expression.text" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.text()</span></code></a> construct:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">text</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="s">&#39;ik_test&#39;</span><span class="p">,</span> <span class="s">&#39;t1&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">text</span><span class="p">(</span><span class="s">&#39;lower(foo)&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.7: </span>support for making use of the
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.expression.text" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">text()</span></code></a> construct in
conjunction with
<a class="reference internal" href="#alembic.operations.Operations.create_index" title="alembic.operations.Operations.create_index"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_index()</span></code></a> in
order to produce functional expressions within CREATE INDEX.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_index.params.index_name"></span><strong>index_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.index_name">¶</a> &#8211; name of the index.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.table_name">¶</a> &#8211; name of the owning table.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.columns"></span><strong>columns</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.columns">¶</a> &#8211; a list consisting of string column names and/or
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.expression.text" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">text()</span></code></a> constructs.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.unique"></span><strong>unique</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.unique">¶</a> &#8211; If True, create a unique index.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.quote"></span><strong>quote</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.quote">¶</a> &#8211; Force quoting of this column&#8217;s name on or off, corresponding
to <code class="docutils literal"><span class="pre">True</span></code> or <code class="docutils literal"><span class="pre">False</span></code>. When left at its default
of <code class="docutils literal"><span class="pre">None</span></code>, the column identifier will be quoted according to
whether the name is case sensitive (identifiers with at least one
upper case character are treated as case sensitive), or if it&#8217;s a
reserved word. This flag is only needed to force quoting of a
reserved word which is not known by the SQLAlchemy dialect.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.**kw">¶</a> &#8211; Additional keyword arguments not mentioned above are
dialect specific, and passed in the form
<code class="docutils literal"><span class="pre">&lt;dialectname&gt;_&lt;argname&gt;</span></code>.
See the documentation regarding an individual dialect at
<a class="reference external" href="http://www.sqlalchemy.org/docs/dialects/index.html#dialect-toplevel" title="(in SQLAlchemy v1.0)"><span>Dialects</span></a> for detail on documented arguments.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; index_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_primary_key">
<code class="descname">create_primary_key</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>columns</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_primary_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create primary key&#8221; instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_primary_key</span><span class="p">(</span>
            <span class="s">&quot;pk_my_table&quot;</span><span class="p">,</span> <span class="s">&quot;my_table&quot;</span><span class="p">,</span>
            <span class="p">[</span><span class="s">&quot;id&quot;</span><span class="p">,</span> <span class="s">&quot;version&quot;</span><span class="p">]</span>
        <span class="p">)</span>
</pre></div>
</div>
<p>This internally generates a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> object
containing the necessary columns, then generates a new
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#sqlalchemy.schema.PrimaryKeyConstraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></code></a>
object which it then associates with the
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a>.
Any event listeners associated with this action will be fired
off normally.   The <a class="reference external" href="http://www.sqlalchemy.org/docs/core/ddl.html#sqlalchemy.schema.AddConstraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">AddConstraint</span></code></a>
construct is ultimately used to generate the ALTER statement.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_primary_key.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_primary_key.params.name">¶</a> &#8211; Name of the primary key constraint.  The name is necessary
so that an ALTER statement can be emitted.  For setups that
use an automated naming scheme such as that described at
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#constraint-naming-conventions" title="(in SQLAlchemy v1.0)"><span>Configuring Constraint Naming Conventions</span></a>
<code class="docutils literal"><span class="pre">name</span></code> here can be <code class="docutils literal"><span class="pre">None</span></code>, as the event listener will
apply the name to the constraint object when it is associated
with the table.</li>
<li><span class="target" id="alembic.operations.Operations.create_primary_key.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_primary_key.params.table_name">¶</a> &#8211; String name of the target table.</li>
<li><span class="target" id="alembic.operations.Operations.create_primary_key.params.columns"></span><strong>columns</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_primary_key.params.columns">¶</a> &#8211; a list of string column names to be applied to the
primary key constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_primary_key.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_primary_key.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>cols -&gt; columns</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_table">
<code class="descname">create_table</code><span class="sig-paren">(</span><em>table_name</em>, <em>*columns</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_table" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create table&#8221; instruction using the current migration
context.</p>
<p>This directive receives an argument list similar to that of the
traditional <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Table</span></code></a> construct, but without the
metadata:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">,</span> <span class="n">NVARCHAR</span><span class="p">,</span> <span class="n">Column</span>
<span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>

<span class="n">op</span><span class="o">.</span><span class="n">create_table</span><span class="p">(</span>
    <span class="s">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;description&#39;</span><span class="p">,</span> <span class="n">NVARCHAR</span><span class="p">(</span><span class="mi">200</span><span class="p">)),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;timestamp&#39;</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">func</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Note that <a class="reference internal" href="#alembic.operations.Operations.create_table" title="alembic.operations.Operations.create_table"><code class="xref py py-meth docutils literal"><span class="pre">create_table()</span></code></a> accepts
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Column" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Column</span></code></a>
constructs directly from the SQLAlchemy library.  In particular,
default values to be created on the database side are
specified using the <code class="docutils literal"><span class="pre">server_default</span></code> parameter, and not
<code class="docutils literal"><span class="pre">default</span></code> which only specifies Python-side defaults:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">func</span>

<span class="c"># specify &quot;DEFAULT NOW&quot; along with the &quot;timestamp&quot; column</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_table</span><span class="p">(</span><span class="s">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;timestamp&#39;</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">func</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The function also returns a newly created
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> object, corresponding to the table
specification given, which is suitable for
immediate SQL operations, in particular
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-meth docutils literal"><span class="pre">Operations.bulk_insert()</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">,</span> <span class="n">NVARCHAR</span><span class="p">,</span> <span class="n">Column</span>
<span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>

<span class="n">account_table</span> <span class="o">=</span> <span class="n">op</span><span class="o">.</span><span class="n">create_table</span><span class="p">(</span>
    <span class="s">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;description&#39;</span><span class="p">,</span> <span class="n">NVARCHAR</span><span class="p">(</span><span class="mi">200</span><span class="p">)),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;timestamp&#39;</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">func</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="p">)</span>

<span class="n">op</span><span class="o">.</span><span class="n">bulk_insert</span><span class="p">(</span>
    <span class="n">account_table</span><span class="p">,</span>
    <span class="p">[</span>
        <span class="p">{</span><span class="s">&quot;name&quot;</span><span class="p">:</span> <span class="s">&quot;A1&quot;</span><span class="p">,</span> <span class="s">&quot;description&quot;</span><span class="p">:</span> <span class="s">&quot;account 1&quot;</span><span class="p">},</span>
        <span class="p">{</span><span class="s">&quot;name&quot;</span><span class="p">:</span> <span class="s">&quot;A2&quot;</span><span class="p">,</span> <span class="s">&quot;description&quot;</span><span class="p">:</span> <span class="s">&quot;account 2&quot;</span><span class="p">},</span>
    <span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0.</span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><span class="target" id="alembic.operations.Operations.create_table.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_table.params.table_name">¶</a> &#8211; Name of the table</li>
<li><span class="target" id="alembic.operations.Operations.create_table.params.*columns"></span><strong>*columns</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_table.params.*columns">¶</a> &#8211; collection of <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Column" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Column</span></code></a>
objects within
the table, as well as optional <a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#sqlalchemy.schema.Constraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Constraint</span></code></a>
objects
and <a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#sqlalchemy.schema.Index" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Index</span></code></a> objects.</li>
<li><span class="target" id="alembic.operations.Operations.create_table.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_table.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.create_table.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_table.params.**kw">¶</a> &#8211; Other keyword arguments are passed to the underlying
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Table</span></code></a> object created for the command.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><p>the <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> object corresponding
to the parameters given.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>- the <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a>
object is returned.</p>
</div>
</p>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; table_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_unique_constraint">
<code class="descname">create_unique_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>columns</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_unique_constraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create unique constraint&#8221; instruction using the
current migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_unique_constraint</span><span class="p">(</span><span class="s">&quot;uq_user_name&quot;</span><span class="p">,</span> <span class="s">&quot;user&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s">&quot;name&quot;</span><span class="p">])</span>
</pre></div>
</div>
<p>This internally generates a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> object
containing the necessary columns, then generates a new
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#sqlalchemy.schema.UniqueConstraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">UniqueConstraint</span></code></a>
object which it then associates with the
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a>.
Any event listeners associated with this action will be fired
off normally.   The <a class="reference external" href="http://www.sqlalchemy.org/docs/core/ddl.html#sqlalchemy.schema.AddConstraint" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">AddConstraint</span></code></a>
construct is ultimately used to generate the ALTER statement.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.name">¶</a> &#8211; Name of the unique constraint.  The name is necessary
so that an ALTER statement can be emitted.  For setups that
use an automated naming scheme such as that described at
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/constraints.html#constraint-naming-conventions" title="(in SQLAlchemy v1.0)"><span>Configuring Constraint Naming Conventions</span></a>,
<code class="docutils literal"><span class="pre">name</span></code> here can be <code class="docutils literal"><span class="pre">None</span></code>, as the event listener will
apply the name to the constraint object when it is associated
with the table.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.table_name">¶</a> &#8211; String name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.columns"></span><strong>columns</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.columns">¶</a> &#8211; a list of string column names in the
source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.deferrable">¶</a> &#8211; optional bool. If set, emit DEFERRABLE or
NOT DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.initially">¶</a> &#8211; optional string. If set, emit INITIALLY &lt;value&gt;
when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>source -&gt; table_name</li>
<li>local_cols -&gt; columns</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.drop_column">
<code class="descname">drop_column</code><span class="sig-paren">(</span><em>table_name</em>, <em>column_name</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.drop_column" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;drop column&#8221; instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">drop_column</span><span class="p">(</span><span class="s">&#39;organization&#39;</span><span class="p">,</span> <span class="s">&#39;account_id&#39;</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.drop_column.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.table_name">¶</a> &#8211; name of table</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.column_name"></span><strong>column_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.column_name">¶</a> &#8211; name of column</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.mssql_drop_check"></span><strong>mssql_drop_check</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.mssql_drop_check">¶</a> &#8211; Optional boolean.  When <code class="docutils literal"><span class="pre">True</span></code>, on
Microsoft SQL Server only, first
drop the CHECK constraint on the column using a
SQL-script-compatible
block that selects into a &#64;variable from sys.check_constraints,
then exec&#8217;s a separate DROP CONSTRAINT for that constraint.</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.mssql_drop_default"></span><strong>mssql_drop_default</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.mssql_drop_default">¶</a> &#8211; Optional boolean.  When <code class="docutils literal"><span class="pre">True</span></code>, on
Microsoft SQL Server only, first
drop the DEFAULT constraint on the column using a
SQL-script-compatible
block that selects into a &#64;variable from sys.default_constraints,
then exec&#8217;s a separate DROP CONSTRAINT for that default.</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.mssql_drop_foreign_key"></span><strong>mssql_drop_foreign_key</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.mssql_drop_foreign_key">¶</a> &#8211; <p>Optional boolean.  When <code class="docutils literal"><span class="pre">True</span></code>, on
Microsoft SQL Server only, first
drop a single FOREIGN KEY constraint on the column using a
SQL-script-compatible
block that selects into a &#64;variable from
sys.foreign_keys/sys.foreign_key_columns,
then exec&#8217;s a separate DROP CONSTRAINT for that default.  Only
works if the column has exactly one FK constraint which refers to
it, at the moment.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.2.</span></p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.drop_constraint">
<code class="descname">drop_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>type_=None</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.drop_constraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Drop a constraint of the given name, typically via DROP CONSTRAINT.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.drop_constraint.params.constraint_name"></span><strong>constraint_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_constraint.params.constraint_name">¶</a> &#8211; name of the constraint.</li>
<li><span class="target" id="alembic.operations.Operations.drop_constraint.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_constraint.params.table_name">¶</a> &#8211; table name.</li>
<li><span class="target" id="alembic.operations.Operations.drop_constraint.params.type_"></span><strong>type_</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_constraint.params.type_">¶</a> &#8211; optional, required on MySQL.  can be
&#8216;foreignkey&#8217;, &#8216;primary&#8217;, &#8216;unique&#8217;, or &#8216;check&#8217;.</li>
<li><span class="target" id="alembic.operations.Operations.drop_constraint.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_constraint.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.drop_index">
<code class="descname">drop_index</code><span class="sig-paren">(</span><em>index_name</em>, <em>table_name=None</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.drop_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;drop index&#8221; instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">drop_index</span><span class="p">(</span><span class="s">&quot;accounts&quot;</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.drop_index.params.index_name"></span><strong>index_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_index.params.index_name">¶</a> &#8211; name of the index.</li>
<li><span class="target" id="alembic.operations.Operations.drop_index.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_index.params.table_name">¶</a> &#8211; name of the owning table.  Some
backends such as Microsoft SQL Server require this.</li>
<li><span class="target" id="alembic.operations.Operations.drop_index.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_index.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; index_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.drop_table">
<code class="descname">drop_table</code><span class="sig-paren">(</span><em>table_name</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.drop_table" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;drop table&#8221; instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">drop_table</span><span class="p">(</span><span class="s">&quot;accounts&quot;</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.drop_table.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_table.params.table_name">¶</a> &#8211; Name of the table</li>
<li><span class="target" id="alembic.operations.Operations.drop_table.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_table.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.drop_table.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_table.params.**kw">¶</a> &#8211; Other keyword arguments are passed to the underlying
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Table</span></code></a> object created for the command.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; table_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.execute">
<code class="descname">execute</code><span class="sig-paren">(</span><em>sqltext</em>, <em>execution_options=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.execute" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute the given SQL using the current migration context.</p>
<p>In a SQL script context, the statement is emitted directly to the
output stream.   There is <em>no</em> return result, however, as this
function is oriented towards generating a change script
that can run in &#8220;offline&#8221; mode.  For full interaction
with a connected database, use the &#8220;bind&#8221; available
from the context:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>
<span class="n">connection</span> <span class="o">=</span> <span class="n">op</span><span class="o">.</span><span class="n">get_bind</span><span class="p">()</span>
</pre></div>
</div>
<p>Also note that any parameterized statement here <em>will not work</em>
in offline mode - INSERT, UPDATE and DELETE statements which refer
to literal values would need to render
inline expressions.   For simple use cases, the
<a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">inline_literal()</span></code></a> function can be used for <strong>rudimentary</strong>
quoting of string values.  For &#8220;bulk&#8221; inserts, consider using
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-meth docutils literal"><span class="pre">bulk_insert()</span></code></a>.</p>
<p>For example, to emit an UPDATE statement which is equally
compatible with both online and offline mode:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">table</span><span class="p">,</span> <span class="n">column</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">String</span>
<span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">op</span>

<span class="n">account</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">column</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">op</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
    <span class="n">account</span><span class="o">.</span><span class="n">update</span><span class="p">()</span><span class="o">.</span>\
        <span class="n">where</span><span class="p">(</span><span class="n">account</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="o">==</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s">&#39;account 1&#39;</span><span class="p">))</span><span class="o">.</span>\
        <span class="n">values</span><span class="p">({</span><span class="s">&#39;name&#39;</span><span class="p">:</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s">&#39;account 2&#39;</span><span class="p">)})</span>
        <span class="p">)</span>
</pre></div>
</div>
<p>Note above we also used the SQLAlchemy
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/selectable.html#sqlalchemy.sql.expression.table" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.table()</span></code></a>
and <a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.expression.column" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.column()</span></code></a> constructs to
make a brief, ad-hoc table construct just for our UPDATE
statement.  A full <a class="reference external" href="http://www.sqlalchemy.org/docs/core/metadata.html#sqlalchemy.schema.Table" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Table</span></code></a> construct
of course works perfectly fine as well, though note it&#8217;s a
recommended practice to at least ensure the definition of a
table is self-contained within the migration script, rather
than imported from a module that may break compatibility with
older migrations.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.Operations.execute.params.sql"></span><strong>sql</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.execute.params.sql">¶</a> &#8211; Any legal SQLAlchemy expression, including:</td>
</tr>
</tbody>
</table>
<ul class="simple">
<li>a string</li>
<li>a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.expression.text" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.text()</span></code></a> construct.</li>
<li>a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/dml.html#sqlalchemy.sql.expression.insert" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.insert()</span></code></a> construct.</li>
<li>a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/dml.html#sqlalchemy.sql.expression.update" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.update()</span></code></a>,
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/dml.html#sqlalchemy.sql.expression.insert" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.insert()</span></code></a>,
or <a class="reference external" href="http://www.sqlalchemy.org/docs/core/dml.html#sqlalchemy.sql.expression.delete" title="(in SQLAlchemy v1.0)"><code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.delete()</span></code></a>  construct.</li>
<li>Pretty much anything that&#8217;s &#8220;executable&#8221; as described
in <a class="reference external" href="http://www.sqlalchemy.org/docs/core/tutorial.html#sqlexpression-toplevel" title="(in SQLAlchemy v1.0)"><span>SQL Expression Language Tutorial</span></a>.</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.Operations.execute.params.execution_options"></span><strong>execution_options</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.execute.params.execution_options">¶</a> &#8211; Optional dictionary of
execution options, will be passed to
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/connections.html#sqlalchemy.engine.Connection.execution_options" title="(in SQLAlchemy v1.0)"><code class="xref py py-meth docutils literal"><span class="pre">sqlalchemy.engine.Connection.execution_options()</span></code></a>.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.f">
<code class="descname">f</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.f" title="Permalink to this definition">¶</a></dt>
<dd><p>Indicate a string name that has already had a naming convention
applied to it.</p>
<p>This feature combines with the SQLAlchemy <code class="docutils literal"><span class="pre">naming_convention</span></code> feature
to disambiguate constraint names that have already had naming
conventions applied to them, versus those that have not.  This is
necessary in the case that the <code class="docutils literal"><span class="pre">&quot;%(constraint_name)s&quot;</span></code> token
is used within a naming convention, so that it can be identified
that this particular name should remain fixed.</p>
<p>If the <a class="reference internal" href="#alembic.operations.Operations.f" title="alembic.operations.Operations.f"><code class="xref py py-meth docutils literal"><span class="pre">Operations.f()</span></code></a> is used on a constraint, the naming
convention will not take effect:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="n">Boolean</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">op</span><span class="o">.</span><span class="n">f</span><span class="p">(</span><span class="s">&#39;ck_bool_t_x&#39;</span><span class="p">)))</span>
</pre></div>
</div>
<p>Above, the CHECK constraint generated will have the name
<code class="docutils literal"><span class="pre">ck_bool_t_x</span></code> regardless of whether or not a naming convention is
in use.</p>
<p>Alternatively, if a naming convention is in use, and &#8216;f&#8217; is not used,
names will be converted along conventions.  If the <code class="docutils literal"><span class="pre">target_metadata</span></code>
contains the naming convention
<code class="docutils literal"><span class="pre">{&quot;ck&quot;:</span> <span class="pre">&quot;ck_bool_%(table_name)s_%(constraint_name)s&quot;}</span></code>, then the
output of the following:</p>
<blockquote>
<div>op.add_column(&#8216;t&#8217;, &#8216;x&#8217;, Boolean(name=&#8217;x&#8217;))</div></blockquote>
<p>will be:</p>
<div class="highlight-python"><div class="highlight"><pre>CONSTRAINT ck_bool_t_x CHECK (x in (1, 0)))
</pre></div>
</div>
<p>The function is rendered in the output of autogenerate when
a particular constraint name is already converted, for SQLAlchemy
version <strong>0.9.4 and greater only</strong>.   Even though <code class="docutils literal"><span class="pre">naming_convention</span></code>
was introduced in 0.9.2, the string disambiguation service is new
as of 0.9.4.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.4.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.get_bind">
<code class="descname">get_bind</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.get_bind" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the current &#8216;bind&#8217;.</p>
<p>Under normal circumstances, this is the
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/connections.html#sqlalchemy.engine.Connection" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a> currently being used
to emit SQL to the database.</p>
<p>In a SQL script context, this value is <code class="docutils literal"><span class="pre">None</span></code>. [TODO: verify this]</p>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.get_context">
<code class="descname">get_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.get_context" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a> object that&#8217;s
currently in use.</p>
</dd></dl>

<dl class="classmethod">
<dt id="alembic.operations.Operations.implementation_for">
<em class="property">classmethod </em><code class="descname">implementation_for</code><span class="sig-paren">(</span><em>op_cls</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.implementation_for" title="Permalink to this definition">¶</a></dt>
<dd><p>Register an implementation for a given <a class="reference internal" href="#alembic.operations.MigrateOperation" title="alembic.operations.MigrateOperation"><code class="xref py py-class docutils literal"><span class="pre">MigrateOperation</span></code></a>.</p>
<p>This is part of the operation extensibility API.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="api/operations.html#operation-plugins"><span>Operation Plugins</span></a> - example of use</p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.inline_literal">
<code class="descname">inline_literal</code><span class="sig-paren">(</span><em>value</em>, <em>type_=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.inline_literal" title="Permalink to this definition">¶</a></dt>
<dd><p>Produce an &#8216;inline literal&#8217; expression, suitable for
using in an INSERT, UPDATE, or DELETE statement.</p>
<p>When using Alembic in &#8220;offline&#8221; mode, CRUD operations
aren&#8217;t compatible with SQLAlchemy&#8217;s default behavior surrounding
literal values,
which is that they are converted into bound values and passed
separately into the <code class="docutils literal"><span class="pre">execute()</span></code> method of the DBAPI cursor.
An offline SQL
script needs to have these rendered inline.  While it should
always be noted that inline literal values are an <strong>enormous</strong>
security hole in an application that handles untrusted input,
a schema migration is not run in this context, so
literals are safe to render inline, with the caveat that
advanced types like dates may not be supported directly
by SQLAlchemy.</p>
<p>See <a class="reference internal" href="#alembic.operations.Operations.execute" title="alembic.operations.Operations.execute"><code class="xref py py-meth docutils literal"><span class="pre">execute()</span></code></a> for an example usage of
<a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">inline_literal()</span></code></a>.</p>
<p>The environment can also be configured to attempt to render
&#8220;literal&#8221; values inline automatically, for those simple types
that are supported by the dialect; see
<a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure.params.literal_binds" title="alembic.runtime.environment.EnvironmentContext.configure"><code class="xref py py-paramref docutils literal"><span class="pre">EnvironmentContext.configure.literal_binds</span></code></a> for this
more recently added feature.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.inline_literal.params.value"></span><strong>value</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.inline_literal.params.value">¶</a> &#8211; The value to render.  Strings, integers, and simple
numerics should be supported.   Other types like boolean,
dates, etc. may or may not be supported yet by various
backends.</li>
<li><span class="target" id="alembic.operations.Operations.inline_literal.params.type_"></span><strong>type_</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.inline_literal.params.type_">¶</a> &#8211; optional - a <a class="reference external" href="http://www.sqlalchemy.org/docs/core/type_api.html#sqlalchemy.types.TypeEngine" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.types.TypeEngine</span></code></a>
subclass stating the type of this value.  In SQLAlchemy
expressions, this is usually derived automatically
from the Python type of the value itself, as well as
based on the context in which the value is used.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure.params.literal_binds" title="alembic.runtime.environment.EnvironmentContext.configure"><code class="xref py py-paramref docutils literal"><span class="pre">EnvironmentContext.configure.literal_binds</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.invoke">
<code class="descname">invoke</code><span class="sig-paren">(</span><em>operation</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.invoke" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a <a class="reference internal" href="#alembic.operations.MigrateOperation" title="alembic.operations.MigrateOperation"><code class="xref py py-class docutils literal"><span class="pre">MigrateOperation</span></code></a>, invoke it in terms of
this <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> instance.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8.0.</span></p>
</div>
</dd></dl>

<dl class="classmethod">
<dt id="alembic.operations.Operations.register_operation">
<em class="property">classmethod </em><code class="descname">register_operation</code><span class="sig-paren">(</span><em>name</em>, <em>sourcename=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.register_operation" title="Permalink to this definition">¶</a></dt>
<dd><p>Register a new operation for this class.</p>
<p>This method is normally used to add new operations
to the <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> class, and possibly the
<a class="reference internal" href="#alembic.operations.BatchOperations" title="alembic.operations.BatchOperations"><code class="xref py py-class docutils literal"><span class="pre">BatchOperations</span></code></a> class as well.   All Alembic migration
operations are implemented via this system, however the system
is also available as a public API to facilitate adding custom
operations.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8.0.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="api/operations.html#operation-plugins"><span>Operation Plugins</span></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.rename_table">
<code class="descname">rename_table</code><span class="sig-paren">(</span><em>old_table_name</em>, <em>new_table_name</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.rename_table" title="Permalink to this definition">¶</a></dt>
<dd><p>Emit an ALTER TABLE to rename a table.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.rename_table.params.old_table_name"></span><strong>old_table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.rename_table.params.old_table_name">¶</a> &#8211; old name.</li>
<li><span class="target" id="alembic.operations.Operations.rename_table.params.new_table_name"></span><strong>new_table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.rename_table.params.new_table_name">¶</a> &#8211; new name.</li>
<li><span class="target" id="alembic.operations.Operations.rename_table.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.rename_table.params.schema">¶</a> &#8211; <p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>&#8216;schema&#8217; can now accept a
<a class="reference external" href="http://www.sqlalchemy.org/docs/core/sqlelement.html#sqlalchemy.sql.elements.quoted_name" title="(in SQLAlchemy v1.0)"><code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code></a> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="alembic.operations.BatchOperations">
<em class="property">class </em><code class="descclassname">alembic.operations.</code><code class="descname">BatchOperations</code><span class="sig-paren">(</span><em>migration_context</em>, <em>impl=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations" title="Permalink to this definition">¶</a></dt>
<dd><p>Modifies the interface <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> for batch mode.</p>
<p>This basically omits the <code class="docutils literal"><span class="pre">table_name</span></code> and <code class="docutils literal"><span class="pre">schema</span></code> parameters
from associated methods, as these are a given when running under batch
mode.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.batch_alter_table" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-meth docutils literal"><span class="pre">Operations.batch_alter_table()</span></code></a></p>
</div>
<p>Note that as of 0.8, most of the methods on this class are produced
dynamically using the <a class="reference internal" href="#alembic.operations.Operations.register_operation" title="alembic.operations.Operations.register_operation"><code class="xref py py-meth docutils literal"><span class="pre">Operations.register_operation()</span></code></a>
method.</p>
<p>Construct a new <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.BatchOperations.params.migration_context"></span><strong>migration_context</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.BatchOperations.params.migration_context">¶</a> &#8211; a <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a>
instance.</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="alembic.operations.BatchOperations.add_column">
<code class="descname">add_column</code><span class="sig-paren">(</span><em>column</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.add_column" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue an &#8220;add column&#8221; instruction using the current
batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.add_column" title="alembic.operations.Operations.add_column"><code class="xref py py-meth docutils literal"><span class="pre">Operations.add_column()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.alter_column">
<code class="descname">alter_column</code><span class="sig-paren">(</span><em>column_name</em>, <em>nullable=None</em>, <em>server_default=False</em>, <em>new_column_name=None</em>, <em>type_=None</em>, <em>existing_type=None</em>, <em>existing_server_default=False</em>, <em>existing_nullable=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.alter_column" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue an &#8220;alter column&#8221; instruction using the current
batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.add_column" title="alembic.operations.Operations.add_column"><code class="xref py py-meth docutils literal"><span class="pre">Operations.add_column()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_check_constraint">
<code class="descname">create_check_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>condition</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_check_constraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create check constraint&#8221; instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">source</span></code> and <code class="docutils literal"><span class="pre">schema</span></code>
arguments from the call.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_check_constraint" title="alembic.operations.Operations.create_check_constraint"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_check_constraint()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_foreign_key">
<code class="descname">create_foreign_key</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>referent_table</em>, <em>local_cols</em>, <em>remote_cols</em>, <em>referent_schema=None</em>, <em>onupdate=None</em>, <em>ondelete=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>match=None</em>, <em>**dialect_kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_foreign_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create foreign key&#8221; instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">source</span></code> and <code class="docutils literal"><span class="pre">source_schema</span></code>
arguments from the call.</p>
<p>e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">with</span> <span class="n">batch_alter_table</span><span class="p">(</span><span class="s">&quot;address&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">batch_op</span><span class="p">:</span>
    <span class="n">batch_op</span><span class="o">.</span><span class="n">create_foreign_key</span><span class="p">(</span>
                <span class="s">&quot;fk_user_address&quot;</span><span class="p">,</span>
                <span class="s">&quot;user&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s">&quot;user_id&quot;</span><span class="p">],</span> <span class="p">[</span><span class="s">&quot;id&quot;</span><span class="p">])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_foreign_key" title="alembic.operations.Operations.create_foreign_key"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_foreign_key()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>referent -&gt; referent_table</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_index">
<code class="descname">create_index</code><span class="sig-paren">(</span><em>index_name</em>, <em>columns</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create index&#8221; instruction using the
current batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_index" title="alembic.operations.Operations.create_index"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_index()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_primary_key">
<code class="descname">create_primary_key</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>columns</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_primary_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create primary key&#8221; instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">table_name</span></code> and <code class="docutils literal"><span class="pre">schema</span></code>
arguments from the call.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_primary_key" title="alembic.operations.Operations.create_primary_key"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_primary_key()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_unique_constraint">
<code class="descname">create_unique_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>columns</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_unique_constraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;create unique constraint&#8221; instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">source</span></code> and <code class="docutils literal"><span class="pre">schema</span></code>
arguments from the call.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_unique_constraint" title="alembic.operations.Operations.create_unique_constraint"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_unique_constraint()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.drop_column">
<code class="descname">drop_column</code><span class="sig-paren">(</span><em>column_name</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.drop_column" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;drop column&#8221; instruction using the current
batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.drop_column" title="alembic.operations.Operations.drop_column"><code class="xref py py-meth docutils literal"><span class="pre">Operations.drop_column()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.drop_constraint">
<code class="descname">drop_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>type_=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.drop_constraint" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;drop constraint&#8221; instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">table_name</span></code> and <code class="docutils literal"><span class="pre">schema</span></code>
arguments from the call.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.drop_constraint" title="alembic.operations.Operations.drop_constraint"><code class="xref py py-meth docutils literal"><span class="pre">Operations.drop_constraint()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.drop_index">
<code class="descname">drop_index</code><span class="sig-paren">(</span><em>index_name</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.drop_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a &#8220;drop index&#8221; instruction using the
current batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.drop_index" title="alembic.operations.Operations.drop_index"><code class="xref py py-meth docutils literal"><span class="pre">Operations.drop_index()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; index_name</li>
</ul>
</div>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="alembic.operations.MigrateOperation">
<em class="property">class </em><code class="descclassname">alembic.operations.</code><code class="descname">MigrateOperation</code><a class="headerlink" href="#alembic.operations.MigrateOperation" title="Permalink to this definition">¶</a></dt>
<dd><p>base class for migration command and organization objects.</p>
<p>This system is part of the operation extensibility API.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8.0.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="api/operations.html#operation-objects"><span>Built-in Operation Objects</span></a></p>
<p><a class="reference internal" href="api/operations.html#operation-plugins"><span>Operation Plugins</span></a></p>
<p class="last"><a class="reference internal" href="api/autogenerate.html#customizing-revision"><span>Customizing Revision Generation</span></a></p>
</div>
<dl class="attribute">
<dt id="alembic.operations.MigrateOperation.info">
<code class="descname">info</code><a class="headerlink" href="#alembic.operations.MigrateOperation.info" title="Permalink to this definition">¶</a></dt>
<dd><p>A dictionary that may be used to store arbitrary information
along with this <a class="reference internal" href="#alembic.operations.MigrateOperation" title="alembic.operations.MigrateOperation"><code class="xref py py-class docutils literal"><span class="pre">MigrateOperation</span></code></a> object.</p>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="branches.html"
                        title="previous chapter">Working with Branches</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="cookbook.html"
                        title="next chapter">Cookbook</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/ops.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="cookbook.html" title="Cookbook"
             >next</a> |</li>
        <li class="right" >
          <a href="branches.html" title="Working with Branches"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Alembic 0.8.3 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2010-2015, Mike Bayer.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
    </div>
  </body>
</html>

Zerion Mini Shell 1.0