Django OperationalError

175 views
Skip to first unread message

Petar Pilipovic

unread,
Feb 28, 2015, 1:02:19 AM2/28/15
to django...@googlegroups.com

Hello, I have manage to merge mine application to pythonanywhere.com. After I have done all the needed installing, uploading files, collecting static, making migrations to mine django application, I have experienced an OperationError saying:

no such table: django_session

You can find the rest of mine question here on stackoverflow, Can someone help me over come this error, tank you.
 

James Schneider

unread,
Feb 28, 2015, 1:14:26 AM2/28/15
to django...@googlegroups.com

Generally this happens when you don't apply the initial migration. Have you run 'python manage.py migrate' (assuming Django >= 1.7 since you mentioned making migrations) and if you have, what was the output? If you aren't sure, run it again as it shouldn't hurt anything.

Check your database and make sure that the tables actually exist. If not, and there is no production data (assuming not based on the question), drop and recreate the DB to clear out any previously failed migration attempts and apply your migrations again using the command I specified. Capture the entire output of the command and paste it back to this list so that we can help more.

-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01f5c13c-5b7e-40ea-b98b-e37640e477df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Petar Pilipovic

unread,
Feb 28, 2015, 1:59:50 AM2/28/15
to django...@googlegroups.com
Hello James, will do but I am not at mine lap top atm, gona do it as soon as posible, tank you very much.
> You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/MOsaEEDNyQg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXfPuqKgQz89CVgaB07cf_Lwj%3DK-XcdtV9GK1EZ%3DQxMaQ%40mail.gmail.com.

Petar Pilipovic

unread,
Mar 2, 2015, 11:36:51 PM3/2/15
to django...@googlegroups.com
Hello James, sorry for not uploading mine answer on this mater, I was busy whit something else this day, ok now back to mine Operational Error I have got.
I tried to google some solution to this problem had no luck, and I did what have you told me.
I heave done some
python manage.py sqlflush

and that has gave me this output: 

(django17)04:20 ~/mineDjango$ python manage.py sqlflush BEGIN;DELETE FROM "django_admin_log";DELETE FROM "auth_permission";DELETE FROM "auth_group";DELETE FROM "auth_group_permissions";DELETE FROM "django_session";DELETE FROM "auth_user_groups";DELETE FROM "auth_user_user_permissions";DELETE FROM "account_emailaddress";DELETE FROM "django_site";DELETE FROM "profiles_profile";DELETE FROM "auth_user";DELETE FROM "profiles_userstripe";DELETE FROM "account_emailconfirmation";DELETE FROM "django_content_type";COMMIT;

Then I have done
python manage.py syncdb python manage.py migrate

Output of mine recreating tables are this:
(django17)04:20 ~/mineDjango$ python manage.py syncdbOperations to perform: Synchronize unmigrated apps: allauth, crispy_forms Apply all migrations: account, sessions, admin, sites, profiles, contenttypes, authSynchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes...Running migrations: No migrations to apply.(django17)04:20 ~/mineDjango$ python manage.py migrateOperations to perform: Synchronize unmigrated apps: allauth, crispy_forms Apply all migrations: account, sessions, admin, sites, profiles, contenttypes, authSynchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes...Running migrations: No migrations to apply.
Basically I have had no changes in mine attempt to drop and recreate tables in mine application.
The error is still there.
Error:
Environment:




Request Method: GET
Request URL: http://copser.pythonanywhere.com/


Django Version: 1.7.2
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 
'django.contrib.auth',
 
'django.contrib.contenttypes',
 
'django.contrib.sessions',
 
'django.contrib.messages',
 
'django.contrib.staticfiles',
 
'profiles',
 
'crispy_forms',
 
'django.contrib.sites',
 
'allauth',
 
'allauth.account',
 
'stripe')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 
'django.middleware.common.CommonMiddleware',
 
'django.middleware.csrf.CsrfViewMiddleware',
 
'django.contrib.auth.middleware.AuthenticationMiddleware',
 
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 
'django.contrib.messages.middleware.MessageMiddleware',
 
'django.middleware.clickjacking.XFrameOptionsMiddleware')




Template error:
In template /home/copser/static/templates/home.html, error at line 40
   
no such table: django_session
   
30 :  




   
31 : {% block content %}




   
32 :  <div class="row" style="margin-top: 60px">




   
33 :         <div class="col-md-4">




   
34 :          




   
35 :         </div>




   36 :         <div class="col-md-4">




   37 :          {# <a href="#"> <img class="img-responsive img-rounded" src="{% static 'img/
07.jpg' %}"/> </a> #}




   38 :        </div>




   39 :         <div class="col-md-4">




   40 :          {% if request.user.is_authenticated %}




   41 :             <h3>Hello {{ request.user }}</h3>




   42 :         {% else %}




   43 :           <form class="login" method="POST" action="{% url '
account_login' %}">




   44 :             <input type="hidden" name="csrfmiddlewaretoken" value="sczg1f8U4tWQRa8kgNJC1QsSBKAD9Lvw"> {% csrf_token %}




   45 :                 <div id="div_id_login" class="form-group"><label for="id_login" class="control-label  requiredField">




   46 :                     Login<span class="asteriskField">*</span></label><div class="controls "><input autofocus="autofocus" class="textinput textInput form-control" id="id_login" name="login" placeholder="Username or e-mail" type="text"> </div></div><div id="div_id_password" class="form-group"><label for="id_password" class="control-label  requiredField">




   47 :                     Password<span class="asteriskField">*</span></label><div class="controls "><input class="textinput textInput form-control" id="id_password" name="password" placeholder="Password" type="password"> </div></div><div class="form-group"><div id="div_id_remember" class="checkbox"><label for="id_remember" class=""><input class="checkboxinput checkbox" id="id_remember" name="remember" type="checkbox">




   48 :                     Remember Me




   49 :                     </label>




   50 :                 </div>




Traceback:
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/copser/mineDjango/profiles/views.py" in home
  7.     return render(request, template, context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/shortcuts.py" in render
  48.     return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  174.         return t.render(context_instance)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in render
  148.             return self._render(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in _render
  142.         return self.nodelist.render(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  126.         return compiled_parent._render(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in _render
  142.         return self.nodelist.render(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  305.                     match = condition.eval(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/defaulttags.py" in eval
  898.         return self.value.resolve(context, ignore_failures=True)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in resolve
  596.                 obj = self.var.resolve(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in resolve
  734.             value = self._resolve_lookup(context)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/template/base.py" in _resolve_lookup
  764.                     current = current[bit]
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/utils/functional.py" in inner
  224.             self._setup()
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/utils/functional.py" in _setup
  357.         self._wrapped = self._setupfunc()
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py" in <lambda>
  22.         request.user = SimpleLazyObject(lambda: get_user(request))
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py" in get_user
  10.         request._cached_user = auth.get_user(request)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in get_user
  152.         user_id = request.session[SESSION_KEY]
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in __getitem__
  49.         return self._session[key]
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session
  175.                 self._session_cache = self.load()
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in load
  21.                 expire_date__gt=timezone.now()
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
  92.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/models/query.py" in get
  351.         num = len(clone)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
  122.         self._fetch_all()
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
  966.             self._result_cache = list(self.iterator())
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  265.         for row in compiler.results_iter():
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
  700.         for rows in self.execute_sql(MULTI):
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  786.             cursor.execute(sql, params)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  81.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
  94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)
File "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
  485.         return Database.Cursor.execute(self, query, params)


Exception Type: OperationalError at /
Exception Value: no such table: django_session
Mine question is can you tell why is this happening, and why is there an error on line 40 in mine home.html page.
Is it maybe because I am using Sql3 insted of postgresql?
Tank you
Best
Petar
On Saturday, 28 February 2015 07:59:50 UTC+1, Petar Pilipovic wrote:
Hello James, will do but I am not at mine lap top atm, gona do it as soon as posible, tank you very much.

On Saturday, February 28, 2015, James Schneider <jrschn...@gmail.com> wrote:
> Generally this happens when you don't apply the initial migration. Have you run 'python manage.py migrate' (assuming Django >= 1.7 since you mentioned making migrations) and if you have, what was the output? If you aren't sure, run it again as it shouldn't hurt anything.
>
> Check your database and make sure that the tables actually exist. If not, and there is no production data (assuming not based on the question), drop and recreate the DB to clear out any previously failed migration attempts and apply your migrations again using the command I specified. Capture the entire output of the command and paste it back to this list so that we can help more.
>
> -James
>
> On Feb 27, 2015 10:02 PM, "Petar Pilipovic" <iam...@gmail.com> wrote:
>>
>> Hello, I have manage to merge mine application to pythonanywhere.com. After I have done all the needed installing, uploading files, collecting static, making migrations to mine django application, I have experienced an OperationError saying:
>>
>> no such table: django_session
>> You can find the rest of mine question here on stackoverflow, Can someone help me over come this error, tank you.
>>  
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01f5c13c-5b7e-40ea-b98b-e37640e477df%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/MOsaEEDNyQg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

Collin Anderson

unread,
Mar 6, 2015, 5:21:53 PM3/6/15
to django...@googlegroups.com
Hi,

The problem is that django_session doesn't exist in your database. Either it was never created or it was created and then later deleted.

Does running manage.py migrate re-create it?

Collin
>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01f5c13c-5b7e-40ea-b98b-e37640e477df%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/MOsaEEDNyQg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

Petar Pilipovic

unread,
Mar 6, 2015, 11:24:19 PM3/6/15
to django...@googlegroups.com
Hello Collin,
No the problem is, i have tried to drop mine migrations whit python manage sqlflush, then I have recreate the db whit 
python manage.py migrate.
Here this is the all operation whit python manage sqlflush, syncdb, migrate. I have notice that there was no migration to apply at the end, and the error is still there.
Is there something else I can do, or how can I approach this differently.
Best
Petar

Collin Anderson

unread,
Mar 10, 2015, 1:00:31 PM3/10/15
to django...@googlegroups.com
Hi Petar,

I'm actually not sure why you want to call sqlflush. If you're trying to clear out the database, you may need to delete the migrations table manually, but it just might be simpler to delete the either database and re-create it, rather than the individual tables.

Collin

Petar Pilipovic

unread,
Mar 10, 2015, 1:49:59 PM3/10/15
to django...@googlegroups.com

Heh, lol, Ok tax Collin I will do that. I was thinking that i need to delete mine migration from the terminal, but I will try that, tnx

Petar Pilipovic

unread,
Mar 11, 2015, 2:04:45 AM3/11/15
to django...@googlegroups.com
Hey Collin,
I have done what have you told me, but I still have that error, I even created data base on www.pythonanywhere.com, and amend mine setting.py file to use that db.
I have manually deleted database and done syncdb, migrate etc.
Here are the output for syncdb, and then I have made mine superuser, this is the Operational Error.
Question: Why is he reporting this template rendering error on line 40?
Tank you
Best 
Petar

Collin Anderson

unread,
Mar 12, 2015, 2:23:51 PM3/12/15
to django...@googlegroups.com
Hi,

Do you have the correct file path set to your sqlite3 database? Does it have proper permissions?

I found a similar issue here:

Collin

luis zarate

unread,
Mar 12, 2015, 11:46:35 PM3/12/15
to django...@googlegroups.com
If you deleted your db and created again and the issue persist then maybe the problem is in your apps.

Try removing db, comment 3th party apps in settings and run migrate with only django core apps, put again 3th party apps and run migrate.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e315163-9dc2-4d47-a4de-d8d9f4414fbb%40googlegroups.com.

> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



Petar Pilipovic

unread,
Mar 15, 2015, 11:59:50 PM3/15/15
to django...@googlegroups.com
Solved it, the problem was in 3th party apps, I did as luis recommended, tanks for the help.
all the best,
Petar

Reply all
Reply to author
Forward
0 new messages