35

I am a junior software engineer and am quite new to Django. I built this app and am working on a README to explain to others how to fork, clone and setup the app on their own machines. I've gotten stuck while trying to re-create the steps.

This is the order in which I've drawn up the steps:

  1. Fork and clone the repo
  2. Source a virtual environment
  3. Pip install requirements.txt
  4. Obtain access_token and secret_key and store in secrets.sh
  5. Setup a Postgres DB, create user & database
  6. Migrate (?) - This is where I get stuck!

I tried migrating the app but there are no migrations to apply.

I tried django-admin startproject ig_miner_app . but am getting this error code:

CommandError: /Users/Erin/Desktop/CodeByEAllard/project/instagram_miner/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files

If I can get this sorted out, I should just be able to run the server like normal, right?

I'm sure I'm missing something (or many things) but don't know what they are. I feel silly because I was obviously able to create the app in the first place, but can't figure out how to explain to someone else to do the same! Does any have suggestions for how to get the server to run?

Thank you!

sogu
  • 2,738
  • 5
  • 31
  • 90
allardbrain
  • 599
  • 1
  • 7
  • 14
  • 2
    Why are you running `startproject`? You already have a project! What error are you getting when running `manage.py migrate`? – kaveh May 07 '16 at 21:49
  • I just ran ` startproject ` because I couldn't think of anything else to try. This is the error I get when I run ` python manage.py migrate `: Traceback (most recent call last): File "manage.py", line 8, in from django.core.management import execute_from_command_line ImportError: No module named django.core.management – allardbrain May 07 '16 at 22:26
  • Have you activated your virtual environment? – kaveh May 07 '16 at 22:33
  • Oh yes, virtualenv is definitely activated. – allardbrain May 07 '16 at 23:50

7 Answers7

43

First off, you are getting that error because you are starting a project within the same directory as the cloned project, this directory already contains an app with the name ig_miner_app hence the name conflict.

As regards steps to running the project by other users , this should work.

clone the project

git clone https://github.com/erinallard/instagram_miner.git 

create and start a a virtual environment

virtualenv env --no-site-packages

source env/bin/activate

Install the project dependencies:

pip install -r requirements.txt

create a file named "secrets.sh"

touch secrets.sh (mac and linux)

obtain a secret from MiniWebTool key and add to secrets.sh

export SECRET_KEY='<secret_key>'

add secrets.sh to .gitignore file

create a postgres db and add the credentials to settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'db_name',
        'USER': 'name',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '',
    }
}

then run

python manage.py migrate

create admin account

python manage.py createsuperuser

then

python manage.py makemigrations ig_miner_app

to makemigrations for the app

then again run

python manage.py migrate

to start the development server

python manage.py runserver

and open localhost:8000 on your browser to view the app.

I believe this should get the app up and running on others' machines. Let me know if you get stuck on any of these steps so I make edits, if not, you can just use it and add any other relevant info I might not have added.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Thanks Bernard! I never created a superuser! I'm going to try this fix right now and let you know how it goes. :-) – allardbrain May 07 '16 at 23:51
  • THANK YOU, Bernard! It worked! I am deeply grateful for your detailed help. – allardbrain May 08 '16 at 00:14
  • Hi @BernardParah! First of all, thanks for the great explanation. I have one doubt though: you say you need to create a postgres db, but if the project that is cloned already has a postgres db in place and configured into settings.py, do you need still need to do it? Isn't it enough to make sure the new computer has postgresql installed on the machine? Many thanks in advance! – Giulia Jul 29 '18 at 09:36
  • Hi @Giulia. If the project already has the db settings configured, you will still need to create the database with the same credentials used in the settings. It's not enough for the computer to have it installed. The only way I know that can happen is if you use a db like sqlite. – Bernard 'Beta Berlin' Parah Jul 30 '18 at 12:25
  • when code is deployed, the contents of the db are not pushed, only the schema of the tables which is in the migrations folder – Bernard 'Beta Berlin' Parah Jul 30 '18 at 12:26
  • 1
    @BernardParah this makes sense. Thank you for explaining, I'll get the process done now. – Giulia Jul 30 '18 at 13:34
  • I suppose I could perfectly create the virtual environment before cloning the project? This is my natural setup To setup a cloned project from github 1. Create a virtual environment and activate it 2. Install django and all needed packages 3. Clone the repository with git clone https://github.com// 4. Setup the databse 5. Put database info in settings.py 6. Generate a new secret key, you could use https://djecrety.ir 7. Rename the project, that is the directory that contains settings.py 8. Make your migrations 9. Create a new superuser 10. Final checks – ionecum Mar 01 '22 at 01:36
1

While my hope is that this issue has been resolved by now, if I may, let's revisit something real quick-- I'm sure others have made and, are currently making this mistake.

I tried 'django-admin startproject ig_miner_app . but am getting this error code: "CommandError: " yadda yadda yadda ...

Django actually has amazing documentation. The guys behind it were writers and journalists and not your typical CS guys.

When learning something new, read the documentation. Run through the to-do app tutorial. Here's why:

django-admin startproject

This has already been satisfied if you are pulling a working copy of a pre-existing Application. Your concern should be with this file first and foremost: requirements.txt. This is where the devDependencies state their demands, if you will, similar to package.json.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Abraxas
  • 374
  • 3
  • 10
0

try to pass the app name to the migrate command:

manage.py migrate ig_miner_app
ahmed
  • 5,430
  • 1
  • 20
  • 36
  • This is the error message I get when I try to do that:Traceback (most recent call last): File "manage.py", line 8, in from django.core.management import execute_from_command_line ImportError: No module named django.core.management – allardbrain May 07 '16 at 22:27
0

As you said, once you clone the repo, you have to install the requirements

pip install -r requirements.txt

After that you have to configure the database. Add the details to settings.py

Once it has been done and you have the keys and secrets, you have to make migrations and then migrate.

cd into the app directory and run

python manage.py makemigrations

to create migration files for the models already defined in the codes you have cloned. after that you have to run

python manage.py migrate

to apply the migrations which in effect creates the database tables.

Now you make any changes in models or add extra models or fields, you have to run the last two commands again.

sprksh
  • 2,204
  • 2
  • 26
  • 43
0

My IDE seems to auto-activate a venv if it resides inside the project directory which caused me to continually run into the error when I cloned from git.

ModuleNotFoundError: No module named ''

I had to manually delete the original venv and create a new virtual env then ran these commands. Worked like a PyCharm after :)

pip install -r requirements.txt

python manage.py collectstatic

TechBrad
  • 87
  • 1
  • 3
0
  1. Create virtualenv and activate it.
  2. Install all dependencies.
  3. cd into the project's home directory.
  4. run $ python manage.py runserver.
  • This seems a lot like the [accepted answer](https://stackoverflow.com/a/37094453/6243352), except without the commands or any details or motivating explanations... – ggorlen Feb 13 '22 at 02:10
-1

I take the following steps after cloning the project from GitHub:

pip3 install virtualenv
virtualenv -p python3 env
source env/bin/activate
pip install django
django-admin startproject <mysite>
python manage.py startapp polls 
python manage.py runserver
on terminal: python manage.py makemigrations <app_name>
python manage.py migrate

These work fine on my system.

Igor Cova
  • 3,126
  • 4
  • 31
  • 57
Nidhi Agarwal
  • 428
  • 2
  • 6
  • 17
  • 2
    why would you run `startproject` and `startapp` on a cloned project which is supposed to have already both? – MrCujo Jun 07 '20 at 16:03