OperationalError: no such table on initial syncdb

operationalerror: no such table sqlite3
operationalerror no such table django
django makemigrations no such table
django.db.utils.operationalerror: no such table test
django.db.utils.operationalerror: no such table: django_content_type
operationalerror no such table first_app_topic
django no such table
django.db.utils.operationalerror: no such table: auth_user

I'm running syncdb to create an sqlite db. It was working until recently, and I don't see anything I've changed that would cause it to fail. Mostly I just changed some field names.

I have the following in models.py:

    class GC_User(models.Model):
        first_name = models.CharField(max_length=50)
        last_name = models.CharField(max_length=50)
        email = models.EmailField()
        wp_userID = models.PositiveSmallIntegerField(unique=True)

When I run syncdb after deleting the old db file, I get 150 lines of traceback, the last part of which is:

  File "C:\Python33\lib\site-packages\django\db\backends\util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "C:\Python33\lib\site-packages\django\db\backends\sqlite3\base.py", line 450, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: gameconapp_gc_user

Any thoughts about what might be causing this? I can put in more of the traceback if that would be helpful.


Update: After much digging, my partner determined that the problem was that the application's init.py was getting called. Since a routine there tried to access the GC_User table, it got the no such table error.

For now I've commented it out so I could run syncdb, and once we're in production we won't be resetting the db, but it's counterintuitive to me that the application is being initialized before the database is set up.

I had this issue with a local SQLite 3 database. First I removed the file to be sure.

To solve this issue I used syncdb --no-initial-data then proceeded to use migrate with each app mentioned that was stated to not be synced:

./manage.py syncdb --no-initial-data
./manage.py migrate app1
./manage.py migrate app2
./manage.py migrate app3

There is no guaranteed order so this has to be done manually and just check what order works for you. In my case the simple_email_confirmation app had to be done first before anything else. After a few tries, ./manage.py migrate on its own should work.

django.db.utils.OperationalError: no such table, Try this line: python manage.py migrate --run-syncdb; Feel free to contact First, I've tried OperationalError: no such table: Python_App_user. I'm building a fairly simple application, research, in my Django project that uses Django-CMS. (It's my first ground-up attempt at a project/application.) It's main purpose is to store various intellectual assets (i.e article, book, etc. written by a researcher).

Since you changed field names in the model I assume you are using south to handle the migrations. If that is the case: south does not initialize the database until after syncdb when you run migrate. Django loads all __init__ and models.py files when the sever starts. Any code in these files that requires database access needs to be wrapped in a try/except when they use south.

    #code requiring database access here
except OperationalError:
    #close the database connection

This way you don't have to ever worry about it again if for some reason you need to install with a fresh database again.

Or, since yours is not a reusable app, next time you have to start from scratch just remove the south migrations (they are only required for existing databases).

ContextType in of limit_choices_to clause causing error during initial , python manage.py syncdb (traceback) sqlite3.OperationalError: no such table: django_content_type. My INSTALLED_APPS includes ('django.contrib. auth',� sqlite3.OperationalError: no such table: Python_App_user. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 15, in execute_from_command_line(sys.argv)

Although the discussion is a bit old, I had the same error because I was using ChoiceFields for which choices required a DB connection, for example:

class ExpenseIndividualForm(Form):
  Form to get a specific expense (Individual)
  date = forms.DateField(label=u"Date", initial=datetime.date.today())
  category = forms.ChoiceField(label=u"Catégorie", choices=get_individual_choices())
  employee = forms.ChoiceField(label=u"Utilisateur", choices=get_employee_choices())

for which functions get_individual_choices and get_employee_choice lookup into the database.

When I executed manage syncdb, it imports the classes and executes the initialization codes, which causes a very obscure error.

As proposed by arctelix, protecting the code of these functions inside try... except OperationalError solves the problem

OperatorError no such table : Forums : PythonAnywhere, "OperationalError at / no such table: analysis_predictions" perhaps you could also try removing it to ensure that you're starting clean. There is apparently also a --run-syncdb flag that you can try just to see what happens. To solve this issue I used syncdb --no-initial-data then proceeded to use migrate with each app mentioned that was stated to not be synced:./manage.py syncdb --no-initial-data ./manage.py migrate app1 ./manage.py migrate app2 ./manage.py migrate app3 There is no guaranteed order so this has to be done manually and just check what order works

This error you have encountered since you have changed fields in your models. The table is created prior and is not changed there. So comment out the models and its corresponding and try ./manage.py makemigrations ./manage.py migrate --fake

Now remove the comment and run

./manage.py makemigrations ./manage.py migrate

This must help!

Django: no such table: django_session, django/db/utils operationalerror no such table: django_content_type operationalerror I did use the python manage.py syncdb with no errors and just a "No Fixtures" comment. (It's my first ground-up attempt at a project/application .) It's main� I worked around this by removing djangocms-link from installed apps, sync'ing DBs, and then only installing djangocms-link (now that djangocms parent tables were setup). This comment has been minimized.

Django - no such table exception, django.db.utils.operationalerror: no such table: django_content_type imported, i.e. importing views.py has side effects, then starting from scratch won't work. -- run-syncdb The above exception (no such table: main.auth_user__old) was the� Ugh. Neglect the last comment. You can't get around it this way, you need to add the limit_choices_to *after* you create the target models. And, frankly, it wouldn't make sense any other way because the content types framework has to look it up in the db, this ticket should probably be closed as invalid.

django.db.utils.OperationalError: no such table, OperationalError: no such table: accounts_user same error but when i migrated with --run-syncdb then error goes because it creates accounts_user table but i didn't get that why makemigration & migrate command not did this at first place?! So most probably manage.py migrate creates the tables for snippets before creating the tables for users, despite snippets depend on users. Maybe the cleaner solution would be creating a custom user model in a new Django app and adding the fixtures there, while replacing auth.user with the new user model class.

Error: django.db.utils.OperationalError: no such table, Writing your first Django project applied using a special table in your database called django_migrations) and runs them objects which are recreated automatically from schema every time during syncdb. OperationalError: no such table. The full traceback should show you the code that is trying to read from the auth_user table. Note that Django 1.6.5 is years out of date and missing security fixes.

  • You could initialize your application within try/except and fail silently if the database table isn't set yet. So you don't need to think about uncommenting on production changes
  • I'm not at all familiar with south; I've been mostly teaching myself from the docs with lots of trial and error. It sounds useful. The code I had put in init.py really didn't need to be run on every startup, so I put it on a menu of tasks a manager or admin can run explicitly.
  • @BeverlyBlock it's been a while and did not see your comment. South comes into play when you want to change model fields and NOT have to reset your database. It will migrate your existing database to match the new fields. It's super easy to use and will be part of django in the next release so definitely start using it.