GSWD Heroku Django manage.py issue - django

I worked my way through a great django tutorial online, but am having an issue with the final heroku deployment.
Here is the django tutorial:
http://gettingstartedwithdjango.com/en/lessons/introduction-and-launch/
The issue I have is with the last call to heroku:
heroku python manage.py syncdb
Here is the error I get:
(blog-venv)vagrant#precise64:/vagrant/projects/microblog$ heroku run python manage.py syncdb
Running `python manage.py syncdb` attached to terminal... up, run.2530
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
self.connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py", line 178, in connect
return _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
(blog-venv)vagrant#precise64:/vagrant/projects/microblog$
Any thoughts

As far as I know ( git intermediate level knowledge ) If you forgot to add locals.py to the .gitignore file and committed it then the git repository will have the locals.py file still in it .
You have to remove the file from git repository since it was included in previous commits.
git rm --cached microblog/settings/local.py
Then add microblog/settings/local.py to .gitignore and commit the changes.
Once heroku sees the correct DATABASES setting . Then syncdb works fine
DATABASES = {'default' : dj_database_url.config() }

did you add:
microblog/settings/local.py
to the .gitignore file ?
if that doesn't work try commenting out the DATABASES = {....} bit in the local.py file and see if that works
https://github.com/kennethlove/gswd-transcripts/blob/master/lesson-01.md

Related

ValueError: path is on mount 'C:', start on mount 'F:' while django migrations in windows

I am trying to run the following command
python manage.py makemigrations
But, getting the error
ValueError: path is on mount 'C:', start on mount 'F:'
What can be the reason?
complete traceback:-
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrations.py", line 189, in handle
self.write_migration_files(changes)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrations.py", line 207, in write_migration_files
migration_string = os.path.relpath(writer.path)
File "C:\Python34\lib\ntpath.py", line 579, in relpath
raise ValueError(error)
ValueError: path is on mount 'C:', start on mount 'F:'
The error is occurring because Django is trying to find a relative path between 2 directories and they do not exist (since they are on different drives). This issue is mentioned here: https://bugs.python.org/issue7195. But this response helps to understand the problem: https://bugs.python.org/msg94780.
os.relpath does give you a relative path between two directories.
The problem you are encountering is that, on Windows, a relative path
doesn't even exist if the two directories are on different drives
(which is exactly what the error message says).
When I ran into this error, I was trying to make a migration file for my own app that is located on the F: drive. Running:
python.exe .\manage.py makemigrations
had Django scanning for every change. It located a change for djcelery. This is located in a virtual environment on my C: drive.
To fix this, I just added the app name when calling makemigrations:
python.exe .\manage.py makemigrations <<app_name>>

django via heroku auth_user error

I'm trying to deploy my first small django app to heroku. I'm following a tutorial from djangogirls: http://tutorial.djangogirls.org
I'm able to create the app and login as admin on my local computer. When I deploy to heroku and try to login as admin, I get an error saying there is no such table for auth_user:
OperationalError at /admin/login/
no such table: auth_user
Request Method: POST
Request URL: https://intense-river-2803.herokuapp.com/admin/login/?next=/admin/
Django Version: 1.7.5
Exception Type: OperationalError
Exception Value:
no such table: auth_user
Exception Location: /app/.heroku/python/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py in execute, line 485
Python Executable: /app/.heroku/python/bin/python
Python Version: 2.7.9
Python Path:
['/app',
'/app/.heroku/python/bin',
'/app/.heroku/python/lib/python2.7/site-packages/setuptools-11.3.1-py2.7.egg',
'/app/.heroku/python/lib/python2.7/site-packages/pip-6.0.6-py2.7.egg',
'/app',
'/app/.heroku/python/lib/python27.zip',
'/app/.heroku/python/lib/python2.7',
'/app/.heroku/python/lib/python2.7/plat-linux2',
'/app/.heroku/python/lib/python2.7/lib-tk',
'/app/.heroku/python/lib/python2.7/lib-old',
'/app/.heroku/python/lib/python2.7/lib-dynload',
'/app/.heroku/python/lib/python2.7/site-packages']
Server time: Sat, 28 Feb 2015 15:40:42 -0800
I think I'm able to migrate the database ok, but createsuperuser is a problem.
(env) C:\Users\dougw_000\SkyDrive\MyDjangoSite>heroku run python manage.py migra
te
Running `python manage.py migrate` attached to terminal... up, run.4246
Operations to perform:
Apply all migrations: sessions, contenttypes, blog, admin, auth
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying blog.0001_initial... OK
Applying sessions.0001_initial... OK
(env) C:\Users\dougw_000\SkyDrive\MyDjangoSite>heroku run python manage.py creat
esuperuser
Running `python manage.py createsuperuser` attached to terminal... up, run.3724
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
_init__.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
_init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/b
ase.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/mana
gement/commands/createsuperuser.py", line 55, in execute
return super(Command, self).execute(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/b
ase.py", line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/mana
gement/commands/createsuperuser.py", line 88, in handle
default_username = get_default_username()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/mana
gement/__init__.py", line 174, in get_default_username
auth_app.User._default_manager.get(username=default_username)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager
.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.p
y", line 351, in get
num = len(clone)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.p
y", line 122, in __len__
self._fetch_all()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.p
y", line 966, in _fetch_all
self._result_cache = list(self.iterator())
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.p
y", line 265, in iterator
for row in compiler.results_iter():
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/com
piler.py", line 700, in results_iter
for rows in self.execute_sql(MULTI):
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/com
piler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils
.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils
.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", lin
e 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils
.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/sqlit
e3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: auth_user
(env) C:\Users\dougw_000\SkyDrive\MyDjangoSite>
Firstly, find and delete all pyc files locally. Tell your .gitignore file to ignore pyc files in the future and finally push your changes to heroku.
So, to remove the pyc files, in a UNIX like system (linux, OSX), run this command in your terminal inside your djangogirls folder:
find . -name "*.pyc" -exec rm -rf {} \;
Then go to your .gitignore file and add this line:
*.pyc
Then do:
git add -A .
git commit -m "Remove pyc files"
git push heroku master
The tutorial ommits to tell you to add "*.pyc" to your gitignore and this confuses Heroku, a lot.
I had the same issue and this is how I solved it.
Let me know if it worked!

Heroku Django Postgres syncdb error

Heroko Config
DATABASE_URL: postgres://xxxxxxxx:xxxxxxxxxx#ec2-54-243-215-140.compute-1.amazonaws.com:5432/xxxxxxxxx
HEROKU_POSTGRESQL_GOLD_URL: postgres://yyyyyyyyyyy:yyyyyyyyyyyyy#ec2-54-243-243-20.compute-1.amazonaws.com:5432/yyyyyyyyyy
HEROKU_POSTGRESQL_YELLOW_URL: postgres://zzzzzzzzzz:zzzzzzzzzzzz#ec2-54-243-215-140.compute-1.amazonaws.com:5432/zzzzzzzzz
settings.py
DATABASES = {'default': dj_database_url.config(default='postgres://xxxxxxxx:xxxxxxxxxx#ec2-54-243-215-140.compute-1.amazonaws.com:5432/xxxxxxxxx'),}
heroku run python manage.py syncdb
Running `python manage.py syncdb` attached to terminal... up, run.4673
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 60, in handle_noargs
tables = connection.introspection.table_names()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 910, in table_names
return self.get_table_list(cursor)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/introspection.py", line 33, in get_table_list
AND pg_catalog.pg_table_is_visible(c.oid)""")
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
return self.cursor.execute(query, args)
django.db.utils.DatabaseError: current transaction is aborted, commands ignored until end of transaction block
Many do not speak English and therefore can not explanation. What's the problem?
The error you have posted merely means that there was a previous error in the transaction and the transaction has already aborted. You cannot fix this problem by troubleshooting this error. You must find out what your real problem is and try to fix it.
To do this, check your PostgreSQL logs, and search backwards from this error until you come to a different error. That will be the error that terminated the transaction and you can work on fixing that one instead. This error however is meaningless from a troubleshooting perspective. Find your real problem and fix it.

Running 'syncdb' on heroku for my Django app throws an error

I'm trying to create a Django app on Heroku, as detailed by the Heroku/Django Cedar stack tutorial.
I've gotten to the point where I deploy my code on Heroku, but when I run heroku run python appname/manage.py syncdb, I get the following trace:
Traceback (most recent call last):
File "planamo/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 308, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
self.connection = Database.connect(**conn_params)
File "/app/.heroku/venv/lib/python2.7/site-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I don't know what the problem is. What's going on?
Answered my own question: you have to run heroku addons:add shared-database
I just found another cause for this error. Heroku injects code at the end of settings.py file.
If last line of settings.py don't contains a carry return injected code may be ignored.
This is the case of django-social-auth's settings.py file
You can try to add: 'HOST': '127.0.0.1' in your database config in settings.py

django/postgres: Transaction managed block ended with pending COMMIT/ROLLBACK

I want to run manage.py sqldiff myapp (command from django extension), but I get the following error:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django_extensions/management/commands/sqldiff.py", line 596, in handle
sqldiff_instance.find_differences()
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 222, in inner
self.__exit__(None, None, None)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 207, in __exit__
self.exiting(exc_value, self.using)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 302, in exiting
leave_transaction_management(using=using)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 56, in leave_transaction_management
connection.leave_transaction_management()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in leave_transaction_management
raise TransactionManagementError("Transaction managed block ended with "
django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
manage.py runserver, shell, shell_plus all work fine, but the sqldiff command chokes. I have tried:
restart postgres server
manually connect to postgres from shell via psycopg2, ran
connection.rollback(), and connection.commit()
but the error persists.
Any ideas on what can be done are welcome!
Cheers,
Hoff
I updated an issue with sqldiff causing similar problems. Your best bet is probably to obtain django-extensions from the github repository and do a bit of investigation. Edit sqldiff.py and comment out the transaction code decorating the find_differences method:
# #transaction.commit_manually
def find_differences(self):
...
# transaction.rollback() # reset transaction
...
# transaction.commit()
Now your real problem should be revealed, no longer masked by the transaction exception.