Donut PCs is a website application that uses React and Django
-
Run secret_key.py to get Django secret key
python server/scripts/secret_key.py
-
create a
.env
file withinserver/
cp .env.example .env
-
Enter your PostgreSQL username, password, and Django secret_key in the env file.
POSTGRES_USERNAME="<PostgreSQL Username>" POSTGRES_PASSWORD="<PostgreSQL Password>" SECRET_KEY="<SECRET_KEY>"
This section assumes that PostgreSQL has been installed and configured on you system
-
Create a database in PostgreSQL named
donut_pcs
psql
CREATE DATABASE donut_pcs;
-
Install
virtualenv
on your system.Unix/macOS
python3 -m pip install --user virtualenv
Windows
Before starting, you may need to add python as an environment variable to PATH on your system.
python -m ensurepip
py -m pip install --user virtualenv
-
Create the virtual environment
virutalenv env
-
Run the virtual environment in your system.
Unix/macOS
source env/bin/activate
Windows
.\env\Scripts\activate
If the environment doesn't get activated, open powershell as adminstrator and run the following command first:
Set-ExecutionPolicy RemoteSigned
-
Install the packages in
requirements.txt
.pip install -r requirements.txt
-
Change to the server directory.
cd server
-
Set up and migrate the database.
Prior to running these commands, make sure that your project Environment Variables are set up
python manage.py makemigrations python manage.py migrate
-
Create a superuser (Owner Account)
python manage.py createsuperuser
-
Load the fixtures
Mac/Linux:
python manage.py loaddata items/fixtures/*/*.json
Windows:
foreach ($f in Get-ChildItem .\items\fixtures\*\*.json) { python manage.py loaddata $f.FullName }
-
Change to the server directory.
cd server
-
Run the following command to run the server.
python manage.py runserver
-
How would you flush the database?
Go into the server directory and run the following command.
python manage.py flush
-
How can I reset the database if I'm having issues with
makemigrations
andmigrate
?-
Use
psql
to recreate the database.postgres#= DROP DATABASE donut_pcs; DROP DATABASE postgres#= CREATE DATABASE donut_pcs; CREATE DATABASE
-
Go under every folder in the server folder and empty the migration folder except for
__init__.py
-
Run
makemigrations
andmigrate
.
User data will be lost so you will need to create another superuser and other users you may have created.
-