On Wed, Aug 12, 2015 at 3:13 AM,  <c.bu...@posteo.jp> wrote:
> On 2015-08-11 21:43 Mike Bayer <mike...@zzzcomputing.com> wrote:
>> a relationship() is not a Column.   Alembic "add_column()" is
>> intended to render an "ALTER TABLE <foo> ADD COLUMN <bar>"
>> statement.  You need to pass it a Column object.
>
> Ok, tnen how can I realize that. How can I add a relationship to an
> existing table?
> Is alembic able for that or maybe there is another way to do that?

A "relationship" (in SQLAlchemy terms) is not something that exists in
the database. It is purely a python-level construct for connecting
objects. In the database, relationships are normally represented by
foreign keys.

I don't really understand what you are trying to achieve in your
script above. It seems like you are trying to use Alembic to configure
the way you map classes to database tables, as well as how the tables
themselves are constructed, which doesn't really make sense. Normally
you would use alembic in a migration script which is completely
separate from your application, and simply creates and alters tables.
In your main application, you would change the definition of your
Model classes to match the new table structures.

So for example, if your original application had the Model and Sub
classes, but nothing linking them, then your migration script would
create the "model_sub_relation" table. In your main application you
would add the definition of model_sub_relation table, and add
something like this to the Model class:

    subs = sao.relationship("Sub", secondary=model_sub_relation,
backref="model")

Hope that helps,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to