django no such table:

django.db.utils.operationalerror: no such table test
django no such table: main auth_user old
no such table: django_session
django/db/utils operationalerror no such table django_content_type
django.db.utils.operationalerror: no such table: auth_user
no such table pythonanywhere
no such table: polls_question
no such table dynamic_models_modelfieldschema

I have models in Django set up as below.

class Pupil(models.Model):
    forename = models.CharField(max_length=30)
    surname = models.CharField(max_length=30)
    dateofbirth = models.DateField()
    year = models.IntegerField()
    class_group = models.CharField(max_length=30)
    email = models.EmailField(blank=True)
    assignments = models.ManyToManyField('Assignment', verbose_name='related assignments')

    def __unicode__(self):
        return u'%s %s' % (self.forename, self.surname)

class Subject(models.Model):
    name = models.CharField(max_length=30)
    level = models.CharField(max_length=30)
    teachers = models.ManyToManyField('Teacher', verbose_name='related teachers')

    def __unicode__(self):
        return self.name

class Teacher(models.Model):
    forename = models.CharField(max_length=30)
    surname = models.CharField(max_length=30)
    email = models.EmailField(blank=True)

    def __unicode__(self):
        return u'%s %s' % (self.forename, self.surname)

class Assignment(models.Model):
    assignment_name = models.CharField(max_length=30)
    date_assigned = models.DateField()
    date_submitted = models.DateField()

    def __unicode__(self):
        return self.assignment_name

When I attempt to add a pupil and attach an assignment to the pupil in the admin, I get a database error -

no such table: homework_pupil_assignments

after reading this I realised this could be due to django not updating changes to my models as when I do manage.py sqlall homework

I see the following:

BEGIN;
CREATE TABLE "homework_pupil_assignments" (
    "id" integer NOT NULL PRIMARY KEY,
    "pupil_id" integer NOT NULL,
    "assignment_id" integer NOT NULL,
    UNIQUE ("pupil_id", "assignment_id")
)
;
CREATE TABLE "homework_pupil" (
    "id" integer NOT NULL PRIMARY KEY,
    "forename" varchar(30) NOT NULL,
    "surname" varchar(30) NOT NULL,
    "dateofbirth" date NOT NULL,
    "year" integer NOT NULL,
    "class_group" varchar(30) NOT NULL,
    "email" varchar(75) NOT NULL
)
;
CREATE TABLE "homework_subject_teachers" (
    "id" integer NOT NULL PRIMARY KEY,
    "subject_id" integer NOT NULL,
    "teacher_id" integer NOT NULL,
    UNIQUE ("subject_id", "teacher_id")
)
;
CREATE TABLE "homework_subject" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(30) NOT NULL,
    "level" varchar(30) NOT NULL
)
;
CREATE TABLE "homework_teacher" (
    "id" integer NOT NULL PRIMARY KEY,
    "forename" varchar(30) NOT NULL,
    "surname" varchar(30) NOT NULL,
    "email" varchar(75) NOT NULL
)
;
CREATE TABLE "homework_assignment" (
    "id" integer NOT NULL PRIMARY KEY,
    "assignment_name" varchar(30) NOT NULL,
    "date_assigned" date NOT NULL,
    "date_submitted" date NOT NULL
)
;
COMMIT;

I then installed South, following the directions to get up and running with an existing app, in the hope of successfully syncing these tables. No joy.

Can anyone suggest how I can get the database (sqlite3) to reflect the models or point out what I'm doing wrong?

Updated answer for Django migrations without south plugin:

Like T.T suggested in his answer, my previous answer was for south migration plugin, when Django hasn't any schema migration features. Now (works in Django 1.9+):

T.T wrote:

You can try this!

python manage.py makemigrations

python manage.py migrate --run-syncdb

Outdated for south migrations plugin

As I can see you done it all in wrong order, to fix it up your should complete this checklist (I assume you can't delete sqlite3 database file to start over):

  1. Grab any SQLite GUI tool (i.e. http://sqliteadmin.orbmu2k.de/)
  2. Change your model definition to match database definition (best approach is to comment new fields)
  3. Delete migrations folder in your model
  4. Delete rows in south_migrationhistory table where app_name match your application name (probably homework)
  5. Invoke: ./manage.py schemamigration <app_name> --initial
  6. Create tables by ./manage.py migrate <app_name> --fake (--fake will skip SQL execute because table already exists in your database)
  7. Make changes to your app's model
  8. Invoke ./manage.py schemamigration <app_name> --auto
  9. Then apply changes to database: ./manage.py migrate <app_name>

Steps 7,8,9 repeat whenever your model needs any changes.

Django - no such table exception, I solved the same problem with these steps : Delete your database ( db.sqlite3 in my case) in your project directory; Remove everything from  For django 1.10 you may have to do python manage.py makemigrations appname. improve this answer. answered Nov 23 '16 at 16:13. 26 silver badges. 46 bronze badges. It looks like there was an issue with my migration. I ran ./manage.py schemamigration research --auto and found that many of the fields didn't have a default specified.

You can try this!

python manage.py migrate --run-syncdb

I have the same problem with Django 1.9 and 1.10. This code works!

django no such table:, You can try this! python manage.py makemigrations. python manage.py migrate --run-syncdb  Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

If you are using latest version of django 2.x or 1.11.x then you have to first create migrations ,

python manage.py makemigrations

After that you just have to run migrate command for syncing database .

python manage.py migrate --run-syncdb

These will sync your database and python models and also second command will print all sql behind it.

`no such table: main.catalogue_product__old` when creating a new , Hi, I've ran into a really strange error which I'm not able to debug. On a fresh django-oscar installation (tested with 1.6.4 and 2.0-dev) I'm getting  The above exception (no such table: main.auth_user__old) was the direct cause of the following exception: C:\Users\chris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\exception.py in inner

sqlall just prints the SQL, it doesn't execute it. syncdb will create tables that aren't already created, but it won't modify existing tables.

django.db.utils.OperationalError: no such table, django.db.utils.OperationalError: no such table: layer_classification_classificationmethod #121. Open. didaRo opened this issue on Feb 15,  sometime after creating models , one forget to sync with database . so try to run migration add models to your database. python3 manage.py makemigrations python3 manage.py migrate

One way to sync your database to your django models is to delete your database file and run makemigrations and migrate commands again. This will reflect your django models structure to your database from scratch. Although, make sure to backup your database file before deleting in case you need your records.

This solution worked for me since I wasn't much bothered about the data and just wanted my db and models structure to sync up.

#24248 (django.db.utils.OperationalError: no such table: creating , django.db.utils.OperationalError: no such table: creating models from running manage.py inspectdb. Reported by: Richard Bruskiewich  I have models in Django set up as below. class Pupil(models.Model): forename = models.CharField(max_length=30) surname = models.CharField(max_length=30) dateofbirth = models.DateField

#2631 (pysqlite2.dbapi2.OperationalError: no such table, OperationalError: no such table - SQLite needs full path for settings. as pysqlite can't find the table (i.e. it's assuming we're creating the database). #!/usr/bin/​env python import sys,os # Django bootstrap from http://fnordia.org/?q=node/483​  OperationalError: no such table: Airports. That works fine in a terminal but for some reason python 2.7 no like. I have tried full path, relative path and same directory. No joy. Google shows lot's of same problem but none of the suggested answers works on my linux (Ubuntu 15.04 MATE Desktop Environment 1.8.2) installation.

(Test regressions with sqlite3 3.26.0 (vs 3.25.3)), OperationalError: no such table: main.django_site__old The above exception was the direct cause of the following exception: Traceback (most recent call last):​  FWIW, I hit this bug too in Python 3.7.1, sqlite 3.26.0, and Django 2.1.4. In my case, if I had models with ForeignKeys that related to each other in reverse alphabetic order, I got errors on that looked like: django.db.utils.OperationalError: no such table: main.polls_cat__old

Django admin no such table: django_session : Forums , I've just created a new web app in Django. I try to access the /admin page but I get a 500 error: OperationalError at /admin/ no such table: 

Comments
  • did you do a convert_to_south app_name before you did schemamigration ?
  • Yup. I'm also concerned that if the tables were not synced properly before the integration of South, it'll cause a problem.
  • check in the south_migrationhistory table, and see if this migration is executed or not
  • You should back out your changes to the point where they match what the database looks like, then do the schemamigration --initial. At that point, you should add your changes back in, do another schemamigration --auto and then a migrate
  • how do I find the migrationhistory table?
  • I have dropped all the tables from the shell. I then sync'd and migrated and it seems to have worked.
  • This does not work in Django 1.8.7 as schemamigration is no longer defined as a subcommand for manage.py
  • Actually syncdb is no longer supported in the newer versions of Django and therefore this answer is wrong.