Most web applications have their own database. A database is a collection of data. This is a place in which you will store information about users, your blog posts, etc.
We will be using a PostgreSQL database to store our data. It would be easier to use the default Django database adapter - called sqlite - but it's not good for production use. Production means out on the big, scary internet - running real websites accessed by more than a handful of users. If you want your application to be available to the world, not just running on your computer, you'll need PostgreSQL.
The easiest way to install Postgres on Windows is using a program you can find here: http://www.enterprisedb.com/products-services-training/pgdownload#windows
Choose the newest version available for your operating system. Download the installer, run it and then follow the instructions available here: http://www.postgresqltutorial.com/install-postgresql/. Take note of the installation directory as you will need it in the next step (typically, it's C:\Program Files\PostgreSQL\9.3).
The easiest way is to download the free Postgres.app and install it like any other application on your operating system.
Download it, drag to the Applications folder and run by double clicking. That's it!
You'll also have to add the Postgres command line tools to your PATH variable, what is described here.
Installation steps vary from distribution to distribution. Below are the commands for Ubuntu and Fedora, but if you're using a different distro take a look at the PostgreSQL documentation.
Run the following command:
sudo apt-get install postgresql postgresql-contrib
Run the following command:
sudo yum install postgresql93-server
Next up, we need to create our first database, and a user that can access that database. PostgreSQL lets you create as many databases and users as you like, so if you're running more than one site you should create a database for each one.
If you're using Windows, there's a couple more steps we need to complete. For now it's not important for you to understand the configuration we're doing here, but feel free to ask your coach if you're curious as to what's going on.
- Open the Command Prompt (Start menu → All Programs → Accessories → Command Prompt)
- Run the following by typing it in and hitting return:
setx PATH "%PATH%;C:\Program Files\PostgreSQL\9.3\bin". You can paste things into the Command Prompt by right clicking and selectingPaste. Make sure that the path is the same one you noted during installation with\binadded at the end. You should see the messageSUCCESS: Specified value was saved.. - Close and then reopen the Command Prompt.
First, let's launch the Postgres console by running psql. Remember how to launch the console?
On Mac OS X you can do this by launching the
Terminalapplication (it's in Applications → Utilities). On Linux, it's probably under Applications → Accessories → Terminal. On Windows you need to go to Start menu → All Programs → Accessories → Command Prompt. Furthermore, on Windows,psqlmight require logging in using the username and password you chose during installation. Ifpsqlis asking you for a password and doesn't seem to work, trypsql -U <username> -Wfirst and enter the password later.
$ psql
psql (9.3.4)
Type "help" for help.
#
Our $ now changed into #, which means that we're now sending commands to PostgreSQL. Let's create a user:
# CREATE USER name;
CREATE ROLE
Replace name with your own name. You shouldn't use accented letters or whitespace (e.g. bożena maria is invalid - you need to convert it into bozena_maria).
Now it's time to create a database for your Django project:
# CREATE DATABASE djangogirls OWNER name;
CREATE DATABASE
Remember to replace name with the name you've chosen (e.g. bozena_maria).
Great - that's databases all sorted!