Last active
May 1, 2020 01:20
-
-
Save mostafaghadimi/918935badb5e2e5aa186cce06f5b9ac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have decided to explain the instructions from scratch: | |
1. Install Postgres on your computer. | |
- First install `sudo apt-get install libpq-dev python-dev` which are Postgres dependencies to work with Django perfectly. | |
- Then, enter `sudo apt-get install postgresql postgresql-contrib` command to install Postgres. | |
2. Access to Postgres using `sudo su - postgres` command. | |
3. Create a new database. `createdb <dbname>` | |
4. Create a database user (with password). `createuser -P <username>` | |
5. Access the shell using `psql` command. | |
6. Grant this new user access to your new database with `GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <username>;` command. | |
7. Dump existing data. `python3 manage.py dumpdata > datadump.json` | |
8. Install Postgres package. `pip install psycopg2-binary` | |
9. Change settings.py configuration to the following: | |
```python | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.postgresql_psycopg2', | |
'NAME': '<dbname>', | |
'USER': '<username>', | |
'PASSWORD': '<password>', | |
'HOST': 'localhost', | |
'PORT': '', | |
} | |
} | |
``` | |
10. Make sure you can connect to Postgres DB. `python3 manage.py migrate --run-syncdb` | |
11. Run this on Django shell to exclude contentype data. | |
```python | |
python3 manage.py shell | |
>>> from django.contrib.contenttypes.models import ContentType | |
>>> ContentType.objects.all().delete() | |
>>> quit() | |
``` | |
12. Finally, load your data. `python3 manage.py loaddata datadump.json` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment