Hi Dmitry,
option 3 is the closest one since references between keyed tables *must*
use tablename.fieldname,
but migrate=False should be added to each table unless it is specified in
the DB definition.
Please try again and let us know.
Regards,
Denes
On Wednesday, February 27, 2013 9:39:07 AM UTC-5, Dmitry Mosin wrote:
>
> Hello friends
>
>
> There are a couple of legacy tables.
> I try to create a reference between them.
>
> = 1 ==================================
> db.define_table('m_dsc_cards',
> Field('cardid','string',notnull=True,unique=True),
> primarykey=['cardid'],
> )
>
> db.define_table('m_dsc_clients',
> Field('cn','string'),
> Field('cardid','reference m_dsc_cards'),
> )
>
> <class 'pyodbc.ProgrammingError'> ('42000', "[42000] [FreeTDS][SQL
> Server]Column 'm_dsc_cards.cardid' is not the same data type as referencing
> column 'm_dsc_clients.cardid' in foreign key
> 'm_dsc_clients_cardid__constraint'. (1778) (SQLExecDirectW)")
>
>
>
> = 2 ==================================
> db.define_table('m_dsc_cards',
> Field('cardid','string',notnull=True,unique=True),
> primarykey=['cardid'],
> )
>
> db.define_table('m_dsc_clients',
> Field('cn','string'),
> Field('cardid','reference m_dsc_cards.cardid'),
> )
>
> <class 'pyodbc.ProgrammingError'> ('42000', "[42000] [FreeTDS][SQL
> Server]Foreign key 'm_dsc_clients_cardid__constraint' references invalid
> table 'm_dsc_cards.cardid'. (1767) (SQLExecDirectW)")
>
>
>
> = 3 ==================================
> db.define_table('m_dsc_cards',
> Field('cardid','string',notnull=True,unique=True),
> primarykey=['cardid'],
> )
>
> db.define_table('m_dsc_clients',
> Field('cn','string'),
> Field('cardid','reference m_dsc_cards.cardid'),
> primarykey=['cn'],
> )
>
> <type 'exceptions.TypeError'> argument of type 'bool' is not iterable
>
>
> = 4 ==================================
> db.define_table('m_dsc_cards',
> Field('cardid','string',notnull=True,unique=True),
> primarykey=['cardid'],
> )
>
> db.define_table('m_dsc_clients',
> Field('cn','string'),
> Field('cardid','reference m_dsc_cards'),
> primarykey=['cn'],
> )
>
> Wow! no exception!
> But... field has created with wrong type, INT instead of VARCHAR :(
>
>
>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.