Will & Skill Developers

Will & Skill Developers


Thoughts, snippets and ideas from the team at Will & Skill AB, Stockholm.

Faisal Mahmud
Author

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Share


How to let Django 1.10 create a test database when running `manage.py test`

Faisal MahmudFaisal Mahmud

I ran into some issues when trying to run some tests by calling python manage.py test

1. Allow the django user to create a test database, in this case named test_django

NOTE: test_django is a name set by the Django framework since my the name of my actual database is django

postgres@faisalsmacbook:/home/faisal$ psql  
psql (9.4.11)  
Type "help" for help.

postgres=# ALTER USER django CREATEDB;  
ALTER ROLE  

The command to look for is ALTER USER django CREATEDB; and You should of course change it to ALTER USER <database-user> CREATEDB;

2. Allow the django database user to make the necessary alterations to the database

postgres@faisalsmacbook:~$ psql  
psql (9.4.11)  
Type "help" for help.

postgres=# ALTER DATABASE test_django OWNER TO django;  
ALTER DATABASE  

In the case above we are looking at ALTER DATABASE test_django OWNER TO django; and You should of course change it to ALTER DATABASE <database-name> OWNER TO <database-user>;

You are now ready to run python manage.py test and Django will automatically create a test database and run your tests for You.

Happy coding!

Faisal Mahmud
Author

Faisal Mahmud

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Comments