the error that seems to be popular this week is related to people  
trying to add foreign keys to reflected tables; we dont have unit  
tests set up for this yet so its likely that the tables are getting  
conflicting column objects set up.  the reason it probably doesnt  
work at the table reflection level is because the initalization of  
the ForeignKey object results in an "autoload" of the related table;  
and it probably doesnt set itself up properly, and/or when you later  
go and explcitly autoload the related table, it gets itself confused  
somehow.

you might want to try defining all of your tables first before  
defining any mappers...that way when the Mapper gets a hold of the  
table, it has the latest listing of Column objects on the Table.   
then again that might not fix it.

the error generally means that the Column object which the Mapper  
pulls off the Table at flush time is not the same Column object which  
the mapper had at initialization time, when it first matched up each  
Column to an attribute on the mapped class (which is represented in  
the Mapper via a ColumnProperty).

as a last resort you might have to forego the "autoload" flag (or use  
explicit primaryjoin/secondaryjoin args on each mapper) until i have  
time to insure that reflection deals with newly or re-defined foreign  
keys smoothly.


On Sep 26, 2006, at 7:32 AM, Matias Hermanrud Fjeld wrote:

> Hello.
>
> I'm working with OSCommerce, which has a poorly defined schema. There
> are no foreignkey constraints, so i have redefined the relevant  
> columns
> in SA (see below).
>
> I add some rows, and when flushing i get the following error:
>
> sqlalchemy.exceptions.InvalidRequestError: Column
> 'products_description.products_id' is not available, due to  
> conflicting
> property 'products_id':ColumnProperty 
> (['products_description.products_id'])
>
> What are the usual causes of this type of error?
>
> Here is the code loading the tables and setting up mappings:
>
>     [snip Product and Description class definitions]
>
>     p_d_table = sa.Table('products_description', meta,
>                           sa.Column('products_id', sa.Integer,
>                                     sa.ForeignKey 
> ('products.products_id')),
>                           autoload=True)
>
>     sa.mapper(Description, p_d_table)
>
>     p_table = sa.Table('products', meta,
>                        [snip manufacturers_id column]
>                        autoload=True)
>     sa.mapper(
>         Product, p_table,
>         properties=dict(
>             descriptions=sa.relation(Description),
>             [snip categories relation]
>             )
>         )
>
> Here are the relevant tables:
>
> mysql> describe products;
> +-------------------------+---------------+------+-----+--------- 
> +----------------+
> | Field                   | Type          | Null | Key | Default |
> Extra          |
> +-------------------------+---------------+------+-----+--------- 
> +----------------+
> | products_id             | int(11)       | NO   | PRI | NULL    |
> auto_increment |
> | products_quantity       | int(4)        | NO   |     |
> |                |
> | products_model          | varchar(30)   | YES  |     | NULL
> |                |
> | products_image          | varchar(64)   | YES  |     | NULL
> |                |
> | products_price          | decimal(15,4) | NO   |     |
> |                |
> | products_date_added     | datetime      | NO   | MUL |
> |                |
> | products_last_modified  | datetime      | YES  |     | NULL
> |                |
> | products_date_available | datetime      | YES  |     | NULL
> |                |
> | products_weight         | decimal(5,2)  | NO   |     |
> |                |
> | products_status         | tinyint(1)    | NO   |     |
> |                |
> | products_tax_class_id   | int(11)       | NO   |     |
> |                |
> | manufacturers_id        | int(11)       | YES  |     | NULL
> |                |
> | products_ordered        | int(11)       | NO   |     | 0
> |                |
> | products_distributor    | varchar(20)   | NO   |     |
> |                |
> +-------------------------+---------------+------+-----+--------- 
> +----------------+
>
> mysql> describe products_description;
> +----------------------+--------------+------+-----+--------- 
> +----------------+
> | Field                | Type         | Null | Key | Default |
> Extra          |
> +----------------------+--------------+------+-----+--------- 
> +----------------+
> | products_id          | int(11)      | NO   | PRI | NULL    |
> auto_increment |
> | language_id          | int(11)      | NO   | PRI | 1
> |                |
> | products_name        | varchar(64)  | NO   | MUL |
> |                |
> | products_description | text         | YES  |     | NULL
> |                |
> | products_url         | varchar(255) | YES  |     | NULL
> |                |
> | products_viewed      | int(5)       | YES  |     | 0
> |                |
> +----------------------+--------------+------+-----+--------- 
> +----------------+
>
>
> I'm new to SA, so if I'm missing something obvious, please bear  
> with me.
>
> -- 
> Matias Hermanrud Fjeld
> Copyleft Solutions AS
>
>
> ---------------------------------------------------------------------- 
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to  
> share your
> opinions on IT & business topics through brief surveys -- and earn  
> cash
> http://www.techsay.com/default.php? 
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to