Model Problem with web2py 1.65.0

12 views
Skip to first unread message

Mico Siahaan

unread,
Jul 2, 2009, 6:46:38 PM7/2/09
to web...@googlegroups.com
Hai all,

I am learning web2py. In db.py I activate/create auth_user tables. But
it seemed that web2py failed to generate needed tables.

Here is my db.py

if request.env.web2py_runtime_gae: # if running on Google App Engine
from gluon.contrib.gql import *
### connect to Google BigTable
db = GQLDB()
## and store sessions and tickets there
session.connect(request, response, db=db)
### or use the following lines to store sessions in Memcache
# from gluon.contrib.memdb import MEMDB
# from google.appengine.api.memcache import Client
# session.connect(request, response, db=MEMDB(Client()))
else: # else use a normal relational database
# if not, use SQLite or other DB
#db = SQLDB('sqlite://storage.sqlite')
db = SQLDB('mysql://user:userpasswd@localhost/happo', pool_size=0)

from gluon.tools import *
auth=Auth(globals(),db) # authentication/authorization
auth.define_tables() # creates all needed tables
crud=Crud(globals(),db) # for CRUD helpers using auth
service=Service(globals()) # for json, xml, jsonrpc, xmlrpc, amfrpc

## uncomment as necessary or consult docs for more options
crud.settings.auth=auth # (optional) enforces authorization on crud
mail=Mail() # mailer
mail.settings.server='smtp.gmail.com:587' # your SMTP server
mail.settings.sender='mico.s...@gmail.com' # your email
mail.settings.login='mico.siahaan:gmaipass' # your credentials
auth.settings.mailer=mail # for user email verification
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = True
auth.messages.verify_email = \
'Click on the link
http://127.0.0.1:8000/customer/default/user/verify_email/%(key)s to
verify your email'

and here is the error:

Traceback (most recent call last):
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\restricted.py",
line 107, in restricted
exec ccode in environment
File "C:/Users/mico/Documents/PERSONAL/Project/happo/src/trunk/web2py/applications/customer/controllers/appadmin.py",
line 255, in <module>
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\globals.py",
line 100, in <lambda>
self._caller = lambda f: f()
File "C:/Users/mico/Documents/PERSONAL/Project/happo/src/trunk/web2py/applications/customer/controllers/appadmin.py",
line 104, in insert
if form.accepts(request.vars, session):
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\sqlhtml.py",
line 709, in accepts
onvalidation,
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\html.py",
line 1122, in accepts
status = self._traverse(status)
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\html.py",
line 439, in _traverse
newstatus = c._traverse(status) and newstatus
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\html.py",
line 439, in _traverse
newstatus = c._traverse(status) and newstatus
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\html.py",
line 439, in _traverse
newstatus = c._traverse(status) and newstatus
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\html.py",
line 439, in _traverse
newstatus = c._traverse(status) and newstatus
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\html.py",
line 446, in _traverse
newstatus = self._validate()
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\html.py",
line 935, in _validate
(value, errors) = validator(value)
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\validators.py",
line 305, in __call__
rows = self.dbset(field == value).select(limitby=(0, 1))
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\sql.py",
line 2120, in select
r = response(query)
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\sql.py",
line 2115, in response
self._db._execute(query)
File "C:\Users\mico\Documents\PERSONAL\Project\happo\src\trunk\web2py\gluon\sql.py",
line 730, in <lambda>
self._execute = lambda *a, **b: self._cursor.execute(*a, **b)
File "C:\Python25\Lib\site-packages\MySQLdb\cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "C:\Python25\Lib\site-packages\MySQLdb\connections.py", line
35, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'happo.auth_user' doesn't exist")

Is it a bug in 1.65.0?

--
Mico Siahaan
---
Email: Mico.S...@gmail.com

mdipierro

unread,
Jul 2, 2009, 8:54:48 PM7/2/09
to web2py Web Framework
I do not think so. check if you have a 'happo' somewhere in a
validator. It does not belong there.
> mail.settings.sender='mico.siah...@gmail.com'         # your email
> Email: Mico.Siah...@gmail.com

Mico Siahaan

unread,
Jul 2, 2009, 9:19:10 PM7/2/09
to web...@googlegroups.com
What do you mean by a validator? I did not create new validator. It was my first db.py. For your info, the code work well in SQLite but not in MySQL.

Powered by Telkomsel BlackBerry®

-----Original Message-----
From: mdipierro <mdip...@cs.depaul.edu>

Date: Thu, 2 Jul 2009 17:54:48
To: web2py Web Framework<web...@googlegroups.com>
Subject: [web2py:25520] Re: Model Problem with web2py 1.65.0

Yarko Tymciurak

unread,
Jul 2, 2009, 10:08:03 PM7/2/09
to web...@googlegroups.com
Massimo refers to this:

 File "C:\Python25\Lib\site-
packages\MySQLdb\connections.py", line
35, in defaulterrorhandler
   raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'happo.auth_user' doesn't exist")

when he says "...somewhere in a validator..." - he is guessing at what might be wrong.

What would really help is more details -  what was the application;  what did you do to create them?

Did you create the MySQL db? or was it an existing one?  (sqlite doesn't require creation of db in advance);

If you could be more detailed, we could too ;-)

mdipierro

unread,
Jul 2, 2009, 10:14:55 PM7/2/09
to web2py Web Framework
Could you post the entire model?

Massimo

On Jul 2, 9:08 pm, Yarko Tymciurak <yark...@gmail.com> wrote:
> Massimo refers to this:
>
>  File "C:\Python25\Lib\site-packages\MySQLdb\connections.py", line
> 35, in defaulterrorhandler
>    raise errorclass, errorvalue
> ProgrammingError: (1146, "Table 'happo.auth_user' doesn't exist")
>
> when he says "...somewhere in a validator..." - he is guessing at what might
> be wrong.
>
> What would really help is more details -  what was the application;  what
> did you do to create them?
>
> Did you create the MySQL db? or was it an existing one?  (sqlite doesn't
> require creation of db in advance);
>
> If you could be more detailed, we could too ;-)
>

Mico Siahaan

unread,
Jul 3, 2009, 3:45:40 AM7/3/09
to web...@googlegroups.com
Hi Yarko,

I will try as details as I could :).
1. This is my first try with web2py, basically I just want to make
sample app. It will be a website that member can login and update his
status so other member can know the update
2. For development, I am using win vista business and xampp for
windows (it has apache and mysql)
3. So from xampp control panel I start mysql
4. Then using phpmyadmin I create user, and create database happo.
Give permission for that user to create and modify all tables in happo
database
5. Then I start web2py
6. Create new application
7. Edit db.py. I uncommented lines of auth settings.
8. After that I access index method of appadmin.py controller.
9. Got error tickets

File "C:\Python25\Lib\site-packages\MySQLdb\cursors.py", line 166, in execute
self.errorhandler(self, exc, value)

File "C:\Python25\Lib\site-packages\MySQLdb\connections.py", line


35, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'happo.auth_user' doesn't exist")

while my db.py (full, as requested by massimo)

if request.env.web2py_runtime_gae: # if running on Google App Engine
from gluon.contrib.gql import *
### connect to Google BigTable
db = GQLDB()
## and store sessions and tickets there
session.connect(request, response, db=db)
### or use the following lines to store sessions in Memcache
# from gluon.contrib.memdb import MEMDB
# from google.appengine.api.memcache import Client
# session.connect(request, response, db=MEMDB(Client()))
else: # else use a normal relational database
# if not, use SQLite or other DB
#db = SQLDB('sqlite://storage.sqlite')

db = SQLDB('mysql://my_user:my_passwd@localhost/happo', pool_size=0)

from gluon.tools import *
auth=Auth(globals(),db) # authentication/authorization
auth.define_tables() # creates all needed tables
crud=Crud(globals(),db) # for CRUD helpers using auth
service=Service(globals()) # for json, xml, jsonrpc, xmlrpc, amfrpc

## uncomment as necessary or consult docs for more options
crud.settings.auth=auth # (optional) enforces authorization on crud
mail=Mail() # mailer
mail.settings.server='smtp.gmail.com:587' # your SMTP server

mail.settings.sender='mico.s...@gmail.com' # your email


mail.settings.login='mico.siahaan:gmaipass' # your credentials
auth.settings.mailer=mail # for user email verification
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = True
auth.messages.verify_email = \


so basically I have not done much :)
--
Mico Siahaan
---
Email: Mico.S...@gmail.com

mdipierro

unread,
Jul 3, 2009, 9:49:12 AM7/3/09
to web2py Web Framework
Haha!

> Then using phpmyadmin I create user, and create database happo.

but you did not set

auth.define_tables(migrate=False)

So I am not sure what happened. You tests may have messed up various
things.

What to do?
1) delete database happo
2) delete everything in databases/ folder
3) recreate happo and give the use permission to create/alter tables
4) use auth.define_table(migrate="happo")
5) start you app again
> mail.settings.sender='mico.siah...@gmail.com'         # your email
> mail.settings.login='mico.siahaan:gmaipass'      # your credentials
> auth.settings.mailer=mail         # for user email verification
> auth.settings.registration_requires_verification = False
> auth.settings.registration_requires_approval = True
> auth.messages.verify_email = \
>  'Click on the linkhttp://127.0.0.1:8000/customer/default/user/verify_email/%(key)sto
> verify your email'
>
> so basically I have not done much :)
> --
> Mico Siahaan
> ---
> Email: Mico.Siah...@gmail.com

Mico Siahaan

unread,
Jul 3, 2009, 5:59:23 PM7/3/09
to web...@googlegroups.com
Massimo, thanks it solved. Actually what is 'migrate' parameter
purpose in define_tables function?

regards,

--
Mico Siahaan
---
Email: Mico.S...@gmail.com

Fran

unread,
Jul 3, 2009, 6:54:40 PM7/3/09
to web2py Web Framework
On Jul 3, 10:59 pm, Mico Siahaan <mico.siah...@gmail.com> wrote:
> Massimo, thanks it solved. Actually what is 'migrate' parameter
> purpose in define_tables function?

It allows you to auto-create the database & alter column definitions.

F

mdipierro

unread,
Jul 3, 2009, 7:54:35 PM7/3/09
to web2py Web Framework
it is the same as for define_table() it applies to all tables created
by define_tables()
> Email: Mico.Siah...@gmail.com
Reply all
Reply to author
Forward
0 new messages