3

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>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Doug Smith
  • 500
  • 7
  • 21

1 Answers1

1

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!