web2py already has a mechanism for running scripts that see models.

Did you look into

python web2py.py -S yourapp -M -R script.py

Try

python web2py.py -h

Massimo

On Apr 22, 10:49 am, Álvaro Justen [Turicas] <alvarojus...@gmail.com>
wrote:
> Hello,
> I'm creating a script to do some database verifications. This is
> called script.py and is in web2py root directory.
> To script.py works find I have to modify
> applications/myapp/models/db.py, adding in start:
>
> if __name__ != '__builtin__':
>     from gluon.sql import *
>     from gluon.validators import *
>
> In script.py I have:
>
> from applications.myapp.models.db import *
>
> print 'All values in table X:'
> print db().select(db.X.ALL)
>
> It works fine when I have simple tables but when I have a table X that
> has a reference field to table Y, this script fails:
>
> alv...@jurujuba:~/Desktop/web2py$ ./script.py
> Traceback (most recent call last):
>   File "./script.py", line 4, in <module>
>     from applications.myapp.models.db import *
>   File "/home/alvaro/Desktop/web2py/applications/myapp/models/db.py",
> line 19, in <module>
>     SQLField('y_field', db.Y)
>   File "/home/alvaro/Desktop/web2py/gluon/sql.py", line 938, in define_table
>     raise e
> sqlite3.OperationalError: no such table: X
>
> Am I missing to import anything?
>
> --
>  Álvaro Justen
>  Peta5 - Telecomunicações e Software Livre
>  21 3021-6001 / 9898-0141
>  http://www.peta5.com.br/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to