How do I fix this Django error "Exception Type: OperationalError Exception Value: no such table?"
Asked Answered
B

3

9

I've finally installed all the requirements (so i think!) of a Django project, and I'm trying to get a local install running on my Mac (OSX 10.4).

I'm getting the following error:

Blockquote OperationalError at /
no such table: django_content_type
Request Method: GET
Request URL: http://127.0.0.1:8000/
Exception Type: OperationalError
Exception Value:
no such table: django_content_type
Exception Location: /Users/Diesel/Desktop/DjangoWork/pinax-ev/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py
in execute, line 170
Python Executable: /Users/Diesel/Desktop/DjangoWork/pinax-ev/bin/python
Python Version: 2.5.1

Bans answered 16/5, 2010 at 19:7 Comment(0)
D
11
  • Did you run ./manage.py syncdb to create all your tables?
  • Do you have django.contrib.contenttypes in your INSTALLED_APPS in settings.py?

As an unlikely third option:

  • Does your project/app use the Django app "South"? If so, you would also need to run ./manage.py migrate to make sure all tables get created.

Forgetting any of those items would cause the table(s) for ContentType not to be generated.

Dissidence answered 16/5, 2010 at 19:17 Comment(6)
Thanks! I ended figuring out the ./manage.py syncdb to create tables... Although for some reason the "migrate" command isn't available to me... (I'm using sqlite3, but I'm moving to mysql tonight on my local machine). I actually think i do need "South" where can I find that? Thanks!Bans
the migrate command is added by South. you can find out more about South here: south.aeracode.orgDissidence
Any other reasons why I would get this error? I have checked all the options, but none of them seem to help. This is the line where it goes wrong: 'content_type_id': ContentType.objects.get_for_model(model).pk,Ruination
@Sam Stoelinga That line is probably somehow called before the tables are properly createdEchino
Note: syncdb was removed in Django 1.9Grandam
See this answer for the alternative to syncdb in Django 1.9+Veto
A
13

Using django version 1.10, I had to perform:

python manage.py migrate --run-syncdb
Apothecium answered 16/6, 2017 at 22:42 Comment(0)
D
11
  • Did you run ./manage.py syncdb to create all your tables?
  • Do you have django.contrib.contenttypes in your INSTALLED_APPS in settings.py?

As an unlikely third option:

  • Does your project/app use the Django app "South"? If so, you would also need to run ./manage.py migrate to make sure all tables get created.

Forgetting any of those items would cause the table(s) for ContentType not to be generated.

Dissidence answered 16/5, 2010 at 19:17 Comment(6)
Thanks! I ended figuring out the ./manage.py syncdb to create tables... Although for some reason the "migrate" command isn't available to me... (I'm using sqlite3, but I'm moving to mysql tonight on my local machine). I actually think i do need "South" where can I find that? Thanks!Bans
the migrate command is added by South. you can find out more about South here: south.aeracode.orgDissidence
Any other reasons why I would get this error? I have checked all the options, but none of them seem to help. This is the line where it goes wrong: 'content_type_id': ContentType.objects.get_for_model(model).pk,Ruination
@Sam Stoelinga That line is probably somehow called before the tables are properly createdEchino
Note: syncdb was removed in Django 1.9Grandam
See this answer for the alternative to syncdb in Django 1.9+Veto
W
0

This error comes when your table information is not there in the database or there is some conflict with your existing database. For example you have changed your Database column name or database name. Below steps will help you get rid of this error.

  1. Look for INSTALLED_APPS = [] into the file "setting.py", your app name must be there. for ex: INSTALLED_APPS = ['app'/{whatever is your app name in inverted comma}]

  2. Run the commands:

python manage.py makemigrations app (whatever is your app name-my case- "app")

python manage.py migrate

python manage.py runserver

Woody answered 12/2, 2021 at 16:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.