#How TO set postgres sql as default database for Django:
1.To open postgres in terminal (Alt+T for liux):
>>sudo -u postgres psql
OR:
>>sudo su - postgres
>>psql
2. To create database in postgres :
>>CREATE DATABASE myproject;
#where myproject is name of database you want to open.
3. To create user for database:
>>CREATE USER myprojectuser WITH PASSWORD 'password';
#'myprojectuser' is username for database user.
#'password' is password for database user.
4. AS specified by Django:
>>ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
5. To give permission to user om database:
>>ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
6. AS specified by Django:
ALTER ROLE myprojectuser SET timezone TO 'UTC';
7. To give privileges on database to user :
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
8. To exit postgres:
>>\q
OR
>>exit
on myproject/myproject/settings.py:
#myproject is name of django project
Find:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
And Replace it with:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
No comments:
Post a Comment