On 8/11/15 10:13 PM, 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?
database tables don't have relationships. They have columns. Relationships are only present in Python code, and they act upon a database schema that happens to have the appropriate columns.

What's missing here is that you need to understand the interaction between a Python ORM mapping and what the corresponding database schema looks like. SQLAlchemy doesn't hide or merge together these concepts like other ORMs do; the fact that object A refers to object B is known as a "relationship", but the fact that table "a" refers to table "b" is dealt with using columns and foreign key constraints. The relationship needs that to be happening underneath but you as the programmer have to configure for both concepts.

See the examples in http://docs.sqlalchemy.org/en/rel_1_0/orm/basic_relationships.html where you can see that all models configure both relationship() *AND* the Column objects that are represented in the schema.



Is alembic able for that or maybe there is another way to do that?
Alembic can handle commands for adding the database column and table objects you need.


--
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