On Friday, July 8, 2016 at 5:47:42 PM UTC-7, 黄祥 wrote: > > let say i have a code: > *models/db_wizard_1_bank.py* > db.define_table('bank', > Field('name'), > Field('website'), > format = '%(name)s') > > *controllers/install.py* > def index(): > if db(db.auth_permission).isempty() and db(db.auth_membership).isempty(): > # create index : auth_user > db.executesql('CREATE INDEX idx_auth_user ON auth_user (id, first_name, > last_name, email, username);') > > # insert : bank > db.bank.bulk_insert([ > {'name1' : 'bank0', 'website' : 'http://www.bank0.com'}, > {'name' : 'bank1', 'website' : 'http://www.bank1.com'}, ] ) > > session.flash = T('Installation Done') > redirect(URL('default', 'index') ) > > as you can see, i made a mistake during insert to table bank field name1 > (incorrect), should be field name in table bank, but the traceback error > said is different. > > what i got in traceback error : > > Traceback (most recent call last): > File "/Users/MacBookPro/site/web2py/gluon/restricted.py", line 227, in > restricted > exec ccode in environment > File > "/Users/MacBookPro/site/web2py/applications/test/controllers/install.py" > <http://127.0.0.1:8000/admin/default/edit/mutualfunds/controllers/install.py>, > line 412, in <module> > File "/Users/MacBookPro/site/web2py/gluon/globals.py", line 417, in <lambda> > self._caller = lambda f: f() > File > "/Users/MacBookPro/site/web2py/applications/test/controllers/install.py" > <http://127.0.0.1:8000/admin/default/edit/mutualfunds/controllers/install.py>, > line 9, in index > db.executesql('CREATE INDEX idx_auth_user ON auth_user (id, first_name, > last_name, email, username);') > > This line is saying the first ticket occurs before your insert line. I think it means you previously created an index, and now you're trying to do it again.
I have next-to-no experiences with indexes or indices because my DBs contain only thousands of entries (barely, and often much less). But it looks like the order of statements is not relevant compared to previous activity. /dps > File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/base.py", line > 1019, in executesql > adapter.execute(query) > File > "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/adapters/base.py", > line 1388, in execute > return self.log_execute(*a, **b) > File > "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/adapters/base.py", > line 1382, in log_execute > ret = self.get_cursor().execute(command, *a[1:], **b) > OperationalError: index idx_auth_user already exists > > Error snapshot [image: help] > <http://127.0.0.1:8000/admin/default/ticket/mutualfunds/127.0.0.1.2016-07-09.07-29-57.44b25bca-2458-4de3-b035-ea50bb8f2522#> > > <class 'sqlite3.OperationalError'>(index idx_auth_user already exists) > > again, same code with different structure order (insert first then create > index) in install.py > *controllers/install.py* > def index(): > if db(db.auth_permission).isempty() and db(db.auth_membership).isempty(): > # insert : bank > db.bank.bulk_insert([ > {'name1' : 'bank0', 'website' : 'http://www.bank0.com'}, > {'name' : 'bank1', 'website' : 'http://www.bank1.com'}, ] ) > > # create index : auth_user > db.executesql('CREATE INDEX idx_auth_user ON auth_user (id, first_name, > last_name, email, username);') > > session.flash = T('Installation Done') > redirect(URL('default', 'index') ) > > as you can see, i made a mistake during insert to table bank field name1 > (incorrect), should be field name in table bank, but the traceback error > said is straight to the point to show where is my mistake. > > what i got in traceback error : > > Traceback (most recent call last): > File "/Users/MacBookPro/site/web2py/gluon/restricted.py", line 227, in > restricted > exec ccode in environment > File > "/Users/MacBookPro/site/web2py/applications/test/controllers/install.py" > <http://127.0.0.1:8000/admin/default/edit/mutualfunds/controllers/install.py>, > line 412, in <module> > File "/Users/MacBookPro/site/web2py/gluon/globals.py", line 417, in <lambda> > self._caller = lambda f: f() > File > "/Users/MacBookPro/site/web2py/applications/test/controllers/install.py" > <http://127.0.0.1:8000/admin/default/edit/mutualfunds/controllers/install.py>, > line 55, in index > {'name' : 'bank1', 'website' : 'http://www.bank1.com'}, ] ) > File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", > line 828, in bulk_insert > listify_items = [self._listify(item) for item in items] > File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", > line 641, in _listify > 'Field %s does not belong to the table' % name) > SyntaxError: Field name1 does not belong to the table > > Error snapshot [image: help] > <http://127.0.0.1:8000/admin/default/ticket/mutualfunds/127.0.0.1.2016-07-09.07-33-51.9c11b273-0758-4a3f-b258-e4df76325fda#> > > <type 'exceptions.SyntaxError'>(Field name1 does not belong to the table) > > the solution is either i comment the create index part or change the order > to get the clear traceback error, my question is it normal? > > thanks and best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.