I created a django app on openshift successfully. But, I'm not able to run syncdb using the following deploy hook.
#!/bin/bash
source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate
cd $OPENSHIFT_REPO_DIR/wsgi/$OPENSHIFT_APP_NAME
python manage.py syncdb --noinput
What could be wrong? Please help!
I think its simply because you forget to add the right for file execution with chmod +x filename
Related
Trying to get started with Django on pycharm.
(venv) C:\Users\Vince\PycharmProjects\assignment>python manage.py runserver
But I get this error message whenever i run manage.py:
C:\Users\Vince\AppData\Local\Programs\Python\Python37-32\python.exe: can't open file 'manage.py': [Errno 2] No such file or directory
I do have a django directory opened with a manage.py file in it. Can anyone assist me on what to do?
I have tried other solutions, like:
python -vvvvv manage.py runserver
python manage.py migrate
You need to either specify the exact location of the manage.py file. I.e.:
python3 Users/Vince/Desktop/DjangoProject/manage.py runserver
or cd to the directory it's in and run from there.
cd Users/Vince/Desktop/DjangoProject > python manage.py runserver
I have a Django application running in Heroku. On the initial deployment, I manually migrated the database schema using heroku run.
The next time I needed to push migrations to the app, the release went off without a complaint.
However, when I went to the page to see it live, I was returned a programming error: the new column didn't exist. The migrations had never been run.
Here's my Procfile:
web: gunicorn APP_NAME.wsgi --log-file -
release: python manage.py migrate
release: python manage.py collectstatic --noinput
worker: celery worker -A APP_NAME -B -E -l info
The collectstatic release is run successfully, but the migrate release is seemingly ignored or overlooked. When I manually migrated, they migrated without error. There is an empty __init__.py file in the migrations folder.
If anyone knows what could possibly be hindering the migrate release from running, that would be awesome.
Okay, so I've figured it out. Although in its documentation Heroku seems to imply that there can be more than one release tag in a Procfile, this is untrue.
The last release tag in the Procfile takes precedent.
This means that in order to run multiple commands in the release stage, you have to use a shell script.
Now, my Procfile looks like this:
web: gunicorn APP_NAME.wsgi --log-file -
release: ./release.sh
worker: celery worker -A APP_NAME -B -E -l info
And I have a release.sh script that looks like this:
python manage.py migrate
python manage.py collectstatic --no-input
MAKE SURE TO MAKE YOUR RELEASE.SH SCRIPT EXECUTABLE:
Running chmod u+x release.sh in terminal prior to committing should do the trick.
As I cannot comment #rchurch4's answer, here it is: if you just have a few commands to run at release time, you can use the following in your Procfile:
release: command1 && command2 && command3 [etc.]
for instance
release: python manage.py migrate && python manage.py loaddata foo && python manage.py your_custom_management_command
I'm following an online tutorial in order to learn Django/Python. I'm using PyCharm Community Edition as my IDE. On Windows 10.
When I run python manage.py startapp myapp at the (venv) prompt in terminal window , no error is shown, and \myapp folder is created with the expected content. However, the file db.sqlite3 is not created, and I can't follow through the rest of the tutorial.
What might be going wrong here?
Thank you very much.
when you start a new django app no database must created.
you can run command
python manage.py migrate
to generate database for your project.
default database is sqlite and stored in file named db.sqlite3
Command python manage.py startapp myapp does not create db.sqlite3.
Run:
python manage.py makemigrations
python manage.py migrate
It will automatically create one if not present.
I am a newbie at Django and everytime I try to run (myvenv) C:\Users\lenovo> python manage.py startapp blogit gives me the error:
CommandError: 'blog' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
Am I doing something wrong?
You can't run the command from a directory above your project.
you should do this:
cd projectName
python manage.py startapp blog
With my app I am using flask-script and flask-migrate for database migrations, everything works locally. When, I run
heroku run python manage.py db init
It creates this output:
Running python manage.py db init on ⬢ fpds-scheduler... up, run.1290 (Free)
Creating directory /app/migrations ... done
Creating directory /app/migrations/versions ... done
Generating /app/migrations/README ... done
Generating /app/migrations/script.py.mako ... done
Generating /app/migrations/alembic.ini ... done
Generating /app/migrations/env.py ... done
Please edit configuration/connection/logging settings in '/app/migrations/alembic.ini' before
proceeding.
But when I run heroku run python manage.py db migrate I get an error
alembic.util.exc.CommandError: Path doesn't exist: 'migrations'. Please use the 'init' command to create a new scripts folder.
When I run heroku run bash and look at my directory I can see that there is no migrations folder...
I have tried running giving the command --app fpds-scheduler but that doesn't seem to be working either.
I am not sure what is going wrong?
You must not create the migrations on Heroku itself. The filesystem is ephemeral and anything written programatically will be lost between invocations.
You need to create the migrations locally, commit them to version control, deploy, and only then run them on Heroku.