Hi Anthony,
yes its a legacy database with already filled tables. I want to use
web2py as an web-frontend to access these data and adding data as
well.
I created the database system with the mysql-Workbench and the
'country_has_language'-table was created automatically without an id
field.
Thanks Steffen

On 11 Apr., 16:17, Anthony <[email protected]> wrote:
> On Monday, April 11, 2011 8:45:38 AM UTC-4, Steffen Rhinow wrote:
>
> > Hi
> > have a problem with n:m relationships
> > My problem is that I can not add items to a table, which contains 2
> > primary keys (foreign keys)
> > Imagine I have two tables like
>
> > db.define_table('language',
> >     Field('name','string(50)', notnull=False, default=None),
> >     Field('rfc_code','string(10)', notnull=True, default=None),
> >     migrate=False)
>
> > db.define_table('country',
> >     Field('name','string(100)', notnull=True, default=None),
> >     Field('iso_code','string(8)', notnull=True, default=None),
> >     migrate=False)
>
> > I create a n:m connection with the table
>
> > db.define_table('country_has_language',
> >      Field('country_id', db.country, notnull=True, default=None),
> >      Field('language_id', db.language, notnull=True, default=None),
> >      primarykey=['country_id','language_id'],
> >      migrate=False)
>
> Is this a legacy database with existing data? If not, I don't think you
> need/want to explicitly set the primary key as you have. When web2py creates
> the 'country_has_language' table, it will automatically create an
> autoincrementing id field that will serve as the primary key. 
> Seehttp://web2py.com/book/default/chapter/06#Many-to-Many.
>
> Anthony

Reply via email to