Heroku django app createsuperuser - django

I deployed my django app and when I tried
heroku run python manage.py syncdb
I got a timeout awaiting process error. Superuser is not created for the system yet, though i did syncdb by using:
heroku run:detached python manage.py createsuperuser
But this does not prompt me for the superuser.
Port 5000 is not blocked in my system. How do I make heroku run work (or) how do I create the super user?

do not detach the heroku shell:
heroku run python manage.py createsuperuser
worked for me

after wasting entire day i got the answer
heroku run python manage.py syncdb
doesn't run on institute or office lan to run this you must remove system proxy as well
unset http_proxy
`unset https_proxy`
I hope this will help

Try
heroku run python manage.py shell
And then create your superuser from there. Good luck!

More info please.
What DB are you using?
Have you set your local_settings.py?
Are you using Debian?
I use Postgres on Debian so I had to both apt-get install python-psycopg2 (otherwise you can't use postgres) and pip install --user psycopg2 (otherwise pip freeze misses Postgres), then manually create a user and db. Replace USER with the username from your local_settings.py
sudo su - postgres
createuser USER -dPRs
createdb --owner USER db.db

Related

Django Manage.py Migrate from Google Managed VM Dockerfile - How?

I'm working on a simple implementation of Django hosted on Google's Managed VM service, backed by Google Cloud SQL. I'm able to deploy my application just fine, but when I try to issue some Django manage.py commands within the Dockerfile, I get errors.
Here's my Dockerfile:
FROM gcr.io/google_appengine/python
RUN virtualenv /venv -p python3.4
ENV VIRTUAL_ENV /venv
ENV PATH /venv/bin:$PATH
# Install dependencies.
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
# Add application code.
ADD . /app
# Overwrite the settings file with the PROD variant.
ADD my_app/settings_prod.py /app/my_app/settings.py
WORKDIR /app
RUN python manage.py migrate --noinput
# Use Gunicorn to serve the application.
CMD gunicorn --pythonpath ./my_app -b :$PORT --env DJANGO_SETTINGS_MODULE=my_app.settings my_app.wsgi
# [END docker]
Pretty basic. If I exclude the RUN python manage.py migrate --noinput line, and deploy using the GCloud tool, everything works fine. If I then log onto the VM, I can issue the manage.py migrate command without issue.
However, in the interest of simplifying deployment, I'd really like to be able to issue Django manage.py commands from the Dockerfile. At present, I get the following error if the manage.py statement is included:
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/cloudsql/my_app:us-central1:my_app_prod_00' (2)")
Seems like a simple enough error, but it has me stumped, because the connection is certainly valid. As I said, if I deploy without issuing the manage.py command, everything works fine. Django can connect to the database, and I can issue the command manually on the VM.
I wondering if the reason for my problem is that the sql proxy (cloudsql/) doesn't exist when the Dockerfile is being deployed. If so, how do I get around this?
I'm new to Docker (this being my first attempt) and newish to Django, so I'm unsure of what the correct approach is for handling a deployment of this nature. Should I instead be positioning this command elsewhere?
There are two steps involved in deploying the application.
In the first step, the Dockerfile is used to build the image, which can happen on your machine or on another machine.
In the second step, the created docker image is executed on the Managed VM.
The RUN instruction is executed when the image is being built, not when it's being run.
You should move manage.py to the CMD command, which is run when the image is being run.
CMD python manage.py migrate --noinput && gunicorn --pythonpath ./my_app -b :$PORT --env DJANGO_SETTINGS_MODULE=my_app.settings my_app.wsgi

"Unknown command syncdb" running "python manage.py syncdb"

I want to create the tables of one database called "database1.sqlite", so I run the command:
python manage.py syncdb
but when I execute the command I receive the following error:
Unknown command: 'syncdb'
Type 'manage.py help' for usage.
But when I run
manage.py help
I don`t see any command suspicious to substitute
python manage.py syncdb
Version of Python I use: 3.4.2 Version of Django I use:1.9
I would be very grateful if somebody could help me to solve this issue.
Regards and thanks in advance
If you look at the release notes for django 1.9, syncdb command is removed.
Please use migrate instead. Moving forward, the migration commands would be as documented here
Please note that the django-1.9 release is not stable as of today.
Edit: Django 1.9 is stable now
the new django 1.9 has removed "syncdb",
run "python manage.py migrate",
if you are trying to create a super user, run "python manage.py createsuperuser"
$python manage.py syncdb is deprecated and not supported now.
So instead of this follow below instructions..
Whatever model you have created:
First run:
$python manage.py makemigrations
After running this command you model will be reflected in a migration.
Then you have to run:
$python manage.py migrate
Then run server:
$python manage.py runserver
Now, your project will run perfectly.
In Django 1.9 onwards syncdb command is removed. So instead of use that one, you can use migrate command,eg: python manage.py migrate.Then you can run your server by python manage.py runserver command.
Django has removed python manage.py syncdb command now you can simply use python manage.py makemigrations followed bypython manage.py migrate. The database will sync automatically.
You can run the command from the project folder as: "python.exe manage.py migrate", from a commandline or in a batch-file.
You could also downgrade Django to an older version (before 1.9) if you really need syncdb.
For people trying to run Syncdb from Visual Studio 2015:
The option syncdb was removed from Django 1.9 (deprecated from 1.7), but this option is currently not updated in the context menu of VS2015.
Also, in case you didn't get asked to create a superuser you should manually run this command to create one: python.exe manage.py createsuperuser
Run the command python manage.py makemigratons,and than python manage.py migrate to sync.
Alternarte Way:
Uninstall Django Module from environment
Edit Requirements.txt a type Django<1.9
Run Install from Requirments option in the enviroment
Try Syncdb again
This worked for me.
I also tried this command. Lastly I found the release note from django
Features removed in 1.9
The syncdb command is removed.
Djnago Releases note 1.9
I had the same problem, the only thing worked for me was this command.
python3 manage.py migrate --run-syncdb
Running this got me this result.
Ranvijays-Mac:djangodemo rana.singh$ python3 manage.py migrate --run-syncdb
Operations to perform:
Synchronize unmigrated apps: messages, staticfiles
Apply all migrations: admin, auth, contenttypes, msg, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Running migrations:
Applying msg.0001_initial... OK

Django with AWS - Correct way to syncdb and run scheema migrations using South

In development when I was running django on a local server, I first added South in my installed apps and then did
python manage.py syncdb
After that, whenever I made a change to the database, I'd do
python manage.py scheemamigration
python manage.py migrate appName
I now am using AWS elastic beanstalk and do
git add .
git commit "change made"
git aws.push
to update the aws server. However, I cannot run
python manage.py syncdb
because it says
Unknown command 'syncdb'
so I cannot syncdb and do scheemamigrations. What is the best way for me syncdb and do scheema migrations using South now that I am using AWS servers.
You need to make a container command, heres a snippet from the aws docs...
On your local computer, update your configuration file (e.g., myapp.config) in the > .ebextensions directory.
container_commands:
01_syncdb:
command: "django-admin.py syncdb --migrate --noinput"
leader_only: true
See http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html (Step 6, point number 2) Sorry no anchors in aws docs..
EDIT: Added in migrate flag to syncdb, and changed aws doc reference to a more pertinent one

Heroku Django Postgresql database admin, where is the super user?

I know it's quite newbie, but I just started using heroku. Please bear with me.
If you develop on heroku, it provides you postgresql with username and password.
However when you access it from your django admin page using that, it returns:
relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user..
My question is what do you have to do to create the super user for the admin page?
Thanks in advance.
You can do this
heroku run python manage.py migrate
instead of
heroku run python manage.py syncdb
You can do this from a one off dyno
heroku run python manage.py syncdb
See https://devcenter.heroku.com/articles/getting-started-with-django#syncing-the-database before you do it though.
you have to make makemigrations first and migrate
heroku run python manage.py makemigrations
heroku run python manage.py migrate
and you have to createsuperuser begining
heroku run python manage.py createsuperuser u
username :*florbert
password:######

problems updating DB to heroku with south migrations

I have a Django proyect running in heroku for some time now, the thing is that, tree days ago, I've tryed to update my schema model but, every time I write
heroku run python manage.py migrate quizzer
heroku keeps telling me that everything's up to date, but I've changed my models.py folder and run schema migration as always.
If you know why this is happening or how can I force a schema migration to my heroku app please tell me how.
Ps: I cannot delete the hole database as the data stored in heroku and the data stored in my local server database are not the same, and I don't want to loose the data of my users
Here is a workflow for running a schemamigration on quizzer after modifying your models.py
./manage.py schemamigration quizzer --auto # create migration
./manage.py migrate quizzer # apply migration locally
git add .
git commit -m "Changed quizzer models, added schemamigration"
git push heroku
heroku run python manage.py migrate quizzer # apply migration on heroku
It sounds like you might have forgotten to check your migration file (usually found in appname/migrations) into git, commit it and push it to heroku.
I had this problem too. I solved this by running heroku restart and running the migrate command again. Don't know why it works (suspect it has to do with initial), but at least it works.
Hope that helps!
South might be missing from requirements.txt. Try:
pip freeze > requirements.txt
...followed by another git add/commit/push.
Also, according to the South installation instructions, syncdb must be run first, "to make the South migration-tracking tables". So try:
heroku run python manage.py syncdb
...then try the migrate command again.