Legacy Database how to

April 19, 2010

I’ve a legacy db that I want to run with web2py what should I do ?

  • you must create an auto increment integer field called “id” and make it a PRIMARY KEY.
    This has to be done for every table in your database
  • Then you’ve to take care of references [change them according to the changes you’ve made to the auto increment field which is now called ‘id’]
  • you still need to define it in your model since web2py does not query a db for schemas.
  • 
    db.define_table('legacy_db',
       Field(....),
       Field(....),
       Field(....),
       migrate=False) 
    # migrate=False is a MUST to add not (optional) in case of using a legacy database