Simply connecting to a database does not tell web2py what tables are in the
database. You have to explicitly define the tables by using the DAL
define_table method. So, you code should be:
db=DAL('mysql://varun:[email protected]:3306/test') # note, you should
use DAL(), not SQLDB().
db.define_table('person', <the rest of your table definition>)
# Also, define any additional tables you want to access via the DAL.
Note, db.tables does not extract the names of the actual tables in the db
connection -- it simply lists the names of the DAL Table objects that have
been defined via define_table().
Anthony
On Friday, May 6, 2011 3:49:54 AM UTC-4, vrathore wrote:
> Hello There,
>
> I am connecting to my existing Mysql DB, i am able to connect, but i
> am getting tables empty.
> Here is the Sample Code
> db=SQLDB('mysql://varun:[email protected]:3306/test')
> print db
> print "gettables" ,db.tables
>
> I get the following respose on the console
> database <DAL {'_migrate_enabled': True, '_lastsql': "SET
> sql_mode='NO_BACKSLAS
> H_ESCAPES';", '_db_codec': 'UTF-8', '_timings': [('SET
> FOREIGN_KEY_CHECKS=1;', 0
> .0), ("SET sql_mode='NO_BACKSLASH_ESCAPES';", 0.0)], '_fake_migrate':
> False, '_d
> bname': 'mysql', '_adapter': <gluon.dal.MySQLAdapter object at
> 0x01976670>, 'che
> ck_reserved': None, '_uri': 'mysql://varun:[email protected]:3306/
> test_ytk', '
> tables': [], '_fake_migrate_enabled': False, '_migrate': True,
> '_pool_size': 0}>
>
> "gettables"[]
>
> On the Ticket Response on admin i see this error
> Traceback (most recent call last):
> File "gluon/restricted.py", line 181, in restricted
> File "E:/Projects/Web2Pye/web2py_win/web2py/applications/TSearch/
> models/db.py", line 5, in <module>
> File "gluon/dal.py", line 4042, in __getitem__
> KeyError: 'person'
>