﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10010	ManyToMany programming error	rmaciejczyk@…	nobody	"I'm rather newbie in the django and python programming, but I'm experienced IT guy.
I tried to define data model matching to existing database (Postgresql)
Below you can find my sample code.

{{{
class DBProduct(models.Model):
    name = models.CharField(max_length=128)
    
    class Meta:
        db_table = u'product'

class DBStore(models.Model):
    name = models.CharField(max_length=256)
    sotreproducts = models.ManyToManyField(DBProduct, through='DBStoreProducts')
        
    class Meta:
        db_table = u'singlestore'

class DBStoreProducts(models.Model):
    
    store_conf = models.ForeignKey(DBStore, db_column='store_id', primary_key=True)
    product_id = models.ForeignKey(DBProduct, primary_key=True)
    
    class Meta:
        db_table = u'storeproducts'
}}}


When I execute the following code:

{{{
    store_config = DBStore.objects.get(id=1)
    values = store_config.products.all()

}}}

I get the following Programming Error:


{{{
ProgrammingError
column storeproducts.product_id_id does not exist
LINE 1: ...product"" INNER JOIN ""storeproducts"" ON (""product"".""id"" = ""storeproducts...
}}}

I suppose it's related to the foreign keys configuration in the DBStoreProducts table,
since for the 'store_conf' field a database column name is defined explicitly (store_id),
but for the product_id field not. What I expected was to use a database field named the
same as 'product_id' field.

To sum up when I've changed the model and set the database column name for product id

{{{
    product_id = models.ForeignKey(DBProduct, db_column='product_id' primary_key=True)
}}}

everything seems to go smoothly, so that's obviously ManyToMany field bug.

I'm using Django 1.0.2 (stable release), Python 2.6.1 for Windows.

(BTW. All above examples have been written by hand since I needed to change my quite a secret
table names ;) Sorry for spelling mistakes)
"		closed	Database layer (models, ORM)	1.0		invalid			Unreviewed	0	0	0	0	0	0
