Friday, September 16, 2011

Running Django unit tests

Not being a DBA, or someone who's even really familiar with database administration, I've been banging my head against the wall trying to get unit tests running on my dev box. I'd checked a few posts on SO, but it seems that I'd missed the one most important thing: RTFM.

Got an error creating the test database: permission denied to create database

If you're seeing the above error when running ./manage.py test, read on..

As Django creates and destroys a database when running unit tests, the user that you're using to connect to the server with needs to have permissions to create databases. This cannot be done by granting superuser permissions to the database user (within postgres of course) as the user needs to have database creation by default (you have to SET ROLE when using this method). To grant permissions to create a database by default, you should do this when creating the user account within psql:

create user myuser createdb

No more issues running unit tests.

No comments:

Post a Comment