Hello. I'm having a problem with sqlalchemy and postgresql, and I really don't know what should I do to correct it.
I'm using sqlalchemy. 0.7.3 with postgresql 2.7.2, with the psycopg2 driver and dialect. I'm using the ORM with reflection, and as I renamed a primary key column (from id to product_id), I'm now getting the following exception: sqlalchemy.exc.ArgumentError: Mapper Mapper|Product|product could not assemble any primary key columns for mapped table 'product' Looking through the logs, I've found that the following query is used to find primary keys: SELECT attname FROM pg_attribute WHERE attrelid = ( SELECT indexrelid FROM pg_index i WHERE i.indrelid = %(table_oid)s AND i.indisprimary = 't') ORDER BY attnum I've tried to run this query myself, and the result is 'id', and not 'product_id'. However, when querying the information schema instead of the system tables, I've got the following results: select cu.column_name from information_schema.table_constraints tc inner join information_schema.key_column_usage cu on cu.constraint_name = tc.constraint_name and cu.table_name = tc.table_name and cu.table_schema = tc.table_schema where cu.table_name = 'product' and constraint_type = 'PRIMARY KEY' and cu.table_schema = 'public'; column_name ------------- product_id Is this a postgresql bug for not updating the attribute name in the system catalog ? Why did sqlalchemy choose to query the system tables instead of the information_schema ? I'm not really sure, but it looks like the system tables are not meant to be used for this kind of introspection. Does anyone have any workaround (besides the obvious: remap the table manually) ? Thank you. -- Ronan Dunklau -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.