Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Please note that this is incorrect and over-complicated answer</strong></p> <p>The right way is to use <code>index.create</code> as it was said <a href="https://stackoverflow.com/a/16736472/1296661">here</a>.</p> <hr> <p>First of all make sure that you have latest snapshot of your database and is able to restore database from this snapshot.</p> <p>For medium and large size projects (the ones that you might need to support several versions at the same time and are installed on multiple environments) there is special procedure which is part of database management lifecycle called "database migration". DB migrations includes changes to existing schema. SQLAlchemy doesn't support migration out of the box. </p> <p>There are two SQLAlchemy compatible database migration tools available:</p> <ul> <li><a href="http://alembic.readthedocs.org/" rel="nofollow noreferrer">Alembic</a></li> <li><a href="http://code.google.com/p/sqlalchemy-migrate/" rel="nofollow noreferrer">SQLAlchemy-Migrate</a> </li> </ul> <p>See more information and links to these tools in SQLAlchemy documentation page: <a href="http://docs.sqlalchemy.org/en/latest/core/schema.html#altering-schemas-through-migrations" rel="nofollow noreferrer">Altering Schemas through Migrations</a>.</p> <p>But if your are working on small project I would suggest to manually run ALTER TABLE DDL query from the database command line utility or through connection.execute() in python script.</p> <p>In the production application I'm working at right now, we support only one latest version of application. For every database schema change we do the following steps:</p> <ul> <li>make a snapshot of the production database</li> <li>load this snapshot on development environment</li> <li>update sqlalchemy data model module</li> <li>prepare and run alter table query and save this query for later</li> <li>make other related changes to the code</li> <li>run tests on dev environment</li> <li>deploy latest version of the code to production</li> <li>do alter table on production</li> </ul> <p>Also I'm using the following trick for generating create table/index queries: I point my application to brand new database, enable logging of sqlalchemy queries and run <code>metadata.create_all()</code> - so in logs (or STDOUT) I see create query generated by sqlalchemy</p> <p>Depending on the database system you are using index creation query will be little different. Generic query would look like this:</p> <pre><code>create index targets_i on targets(url); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload