By default, db.define_table() automatically includes an auto-increment 
integer field called "id" to be used as the primary key. If your legacy 
table includes an auto-increment integer field with a different name, then 
you should specify that field as type "id", and the DAL will use that as 
the id field:

legacy_db.define_table('timesheet_client', 
    Field('client_id', 'id'),           

If your legacy table does not include such a field, you need to specify an 
alternative primary key (which entails some limitations on DAL usage with 
the table). See 
http://web2py.com/books/default/chapter/29/6#Legacy-databases-and-keyed-tables 
for 
more details.

Anthony

On Friday, August 10, 2012 4:08:14 AM UTC-4, Spez wrote:
>
> Hi All,
> I am very new to web2py and in general to web framework. 
> I am trying to read a db content from a remote machine, db is mysql, 
> web2py version 1.99.7 stable.
> I have created a new simple application and added a model db1.py with:
>
> legacy_db = DAL('mysql://username:password@my_server:3306/timesheet', 
> migrate_enabled=False, pool_size=20)
> legacy_db.define_table('timesheet_client', 
>     Field('client_id', 'integer'),           
>     Field('organisation', 'string'),         
>     Field('description', 'string'),          
>     Field('address1', 'string'),             
>     Field('city', 'string'),                 
>     Field('state', 'string'),                
>     Field('country', 'string'),              
>     Field('postal_code', 'string'),          
>     Field('contact_first_name', 'string'),   
>     Field('contact_last_name', 'string'),    
>     Field('username', 'string'),             
>     Field('contact_email', 'string'),        
>     Field('phone_number', 'string'),         
>     Field('fax_number', 'string'),           
>     Field('gsm_number', 'string'),           
>     Field('http_url', 'string'),             
>     Field('address2', 'string'),             
>     migrate=False)
>
> then I added to controller default.py:
> def index():
>   return locals()
>   
> def client():
>   clients = 
> legacy_db(legacy_db.timesheet_client).select(orderby=legacy_db.timesheet_client.client_id)
>   return locals()
>
> When I look at page ../my_application/default/client I receive an error:
> <class 'gluon.contrib.pymysql.err.InternalError'> (1054, u"Unknown column '
> timesheet_client.id' in 'field list'")
>
> but I do not have any timesheet_client.id filed in my legacy_db
>
> Any suggestions?
>
>

-- 



Reply via email to