Creating and configuring a database¶
RestAuth uses a relational database to store its data. You can use any database supported by Django.
For RestAuth to use the database, you have to create it, configure it and initialize it.
Creating a database¶
Note
Exhaustive documentation on how to create a database is outside the scope of this document. If in doubt, always consult the official documentation of your database system.
Warning
RestAuth requires a database with transactional support. Most notably, the MyISAM MySQL storage engine (which is the default on many systems), does not support transactions. Please use InnoDB instead.
MySQL¶
Here is an example shell session for creating a MySQL database:
mysql -uroot -pYOUR_PASSWORD -e "CREATE DATABASE restauth CHARACTER SET utf8;"
mysql -uroot -pYOUR_PASSWORD -e "GRANT ALL PRIVILEGES ON restauth.* TO 'restauth'@'localhost'
IDENTIFIED BY 'MYSQL_PASSWORD';"
The correct DATABASES
setting in RestAuth/localsettings.py
then would be:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'restauth',
'USER': 'restauth',
'PASSWORD': 'MYSQL_PASSWORD', # you really should change this!
'HOST': '',
'PORT': '',
}
}
Please also see the MySQL notes (especially the Creating your database chapter) on the subject. The database tables must not use the MyISAM storage engine, please make sure you use InnoDB or any other engine that supports transactions. Django provides some instructions on how to convert a database to InnoDB.
PostgreSQL¶
If you choose to use PostgreSQL, you can create a database like this,
assuming you are already the user postgres
:
createuser -P restauth
psql template1 CREATE DATABASE restauth OWNER restauth ENCODING ‘UTF8’;
The correct DATABASES
setting in RestAuth/localsettings.py
then would be:
DATABASES = {
'default': {
DATABASE_ENGINE = 'django.db.backends.postgresql_psycopg2',
DATABASE_NAME = 'restauth',
DATABASE_USER = 'restauth',
DATABASE_PASSWORD = 'POSTGRES_PASSWORD', # you really should change this!
DATABASE_HOST = '',
DATABASE_PORT = '',
}
}
Please also see the PostgreSQL notes in the Django documentation.
Configuring the database¶
RestAuth uses the standard DATABASES setting of Django. Please also see the notes for specific database systems.
To configure your database, just open RestAuth/localsettings.py
and edit the DATABASES section near
the top of that file.
Initialization¶
Once you have created your database and configured it in RestAuth/localsettings.py
, you can easily
create the necessary tables using the syncdb
and migrate
commands of
restauth-manage.py:
restauth-manage.py syncdb restauth-manage.py migrate