- Run
manager-osx
(for Mac) ormanager-windows
(for Windows)
- Go to Manage Servers
- Ensure that only the PostgreSQL Database is running
- Run
use_djangostack
- For Windows, run
use_djangostack.bat
- For Mac, open Spotlight and run
use_djangostack
- While in the
use_djangostack
terminal:
- Go to the directory containing the
manage.py
file. - Run
python manage.py runserver
. Your server should now be running atlocalhost:8000
.
Instead of copying the SQL statements into the psql
terminal and running it there, you can also run the following command:
psql -U postgres -d djangostack -a -f [.sql filename]
This is especially useful for the database seed files, such as funding.sql
, users.sql
or projects.sql
.
For this command to work, you have to be on the same folder as the .sql
file.
NOTE: This command has a small issue where it doesn't update the pid
/ user_id
sequences, so it breaks the registration/project creation flow. See the fix below.
- Copy
env.example.py
, paste it in the same folder with the nameenv.py
. - Change the PASSWORD string in
env.py
to match your Djangostack installation details.
This means that your database tables do not exist yet. To fix this, follow the steps:
- Run the
use_djangostack
terminal. - Run
psql -U postgres djangostack
, and type in your password. - Copy the relevant content from
schema.sql
(in this repository) and paste in the terminal, press Enter.
When registering a new user or adding new projects, the database attempts to add a pid/user_id
starting from 1 even after inserting the seed data
This happens if we run the seed SQL queries from the bash terminal instead of copy-pasting the queries manually and running them from the psql terminal.
The SERIAL
data type is implemented with a backing Postgres sequence - for our database these sequences are called projects_pid_seq
and users_user_id_seq
.
Whenever we INSERT
into the projects
table, the pid
is automatically set with the next value on the sequence (you can see the next value in the sequence using SELECT nextval('projects_pid_seq')
), and the sequence is also automatically advanced.
When we run the seed SQL queries from the bash terminal, for some reason the backing sequence is not automatically advanced. This results in the next value on the sequence still staying at 1
even when we already have IDs up to 20
(for the users
table) or 100
(for the projects table).
The fix is to manually set the sequence value to the correct number again, and this is done via the setval
call, as such:
SELECT setval('projects_pid_seq', (SELECT MAX(pid) FROM projects));
SELECT setval('users_user_id_seq', (SELECT MAX(user_id) FROM users));