Why doesn't web2py create a PostgreSQL database automatically (curiosity, not criticism)

86 views
Skip to first unread message

Tom Campbell

unread,
Feb 16, 2017, 7:39:35 PM2/16/17
to web2py-users
As a database admin newb last year I had trouble deploying a PostgreSQL site because I forgot that "real" DBMSes require you create a database first, unlike SQLite. So I was trying to create tables in a nonexistent database. Is there some reason web2py doesn't just create a PostgreSQL database with a GUID for a name or something? I'm guessing it's a permissions issue.

This is totally asked out of ignorance. It does not pretend to be informed criticism.

黄祥

unread,
Feb 16, 2017, 8:27:32 PM2/16/17
to web2py-users
pardon, not sure i got what u mean, when starting new project that use postgresql, i usually create the database from the terminal, ensure DAL migrate is true, then hit the web2py app admin once
e.g.
# create database
/Applications/Postgres.app/Contents/Versions/9.4/bin/createdb -O users new_project
# list databases
/Applications/Postgres.app/Contents/Versions/9.4/bin/psql -l

if you want to do it in web2py site, i think you can define a controller function that check if database not exists then execute sql command to create database on postgresql.

best regards,
stifan

Tom Campbell

unread,
Feb 17, 2017, 2:37:27 AM2/17/17
to web2py-users
Thanks, Stifan, you rock as always. I thought I had tried & failed with this but I trust you on these matters more than myself. Can't wait to get to my db machine to re-test

Philip Kilner

unread,
Feb 17, 2017, 4:56:58 AM2/17/17
to web...@googlegroups.com
Hi Tom,

On 17/02/17 00:39, Tom Campbell wrote:
> Is there some reason web2py doesn't just create a PostgreSQL database
> with a GUID for a name or something? I'm guessing it's a permissions issue.
>

As Stifan says, you can script this if you are accessing PostgreSQL as a
user with create db permissions.

Just to add a note of caution though, on a production server - depending
on your environment/security requirements - you may wish to set up
web2py to use an account which only has access to the relevant db.

HTH


--

Regards,

PhilK


'a bell is a cup...until it is struck'

Reply all
Reply to author
Forward
0 new messages