Using PostgreSQL

Throughout this book, we have mostly used the SQLite database. SQLite is simple and quick to set up, but for a production environment you will need a more powerful database, such as PostgreSQL, MySQL, or Oracle. You already learned how to install PostgreSQL and set up a PostgreSQL database in Chapter 3Extending Your Blog Application. If you need to install PostgreSQL, you can read the Installing PostgreSQL section of Chapter 3, Extending Your Blog Application.

Let's create a PostgreSQL user. Open the shell and run the following commands to create a database user:

su postgres
createuser -dP educa

You will be prompted for a password and permissions you want to give to this user. Enter the desired password and permissions and then create a new database with the following command:

createdb -E utf8 -U educa educa

Then edit the settings/pro.py file and modify the DATABASES setting to make it look as follows:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'educa',
'USER': 'educa',
'PASSWORD': '*****',
}
}

Replace the preceding data with the database name and credentials for the user you created. The new database is empty. Run the following command to apply all database migrations:

python manage.py migrate

Finally, create a superuser with the following command:

python manage.py createsuperuser
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset