[Django]-Django no such table:

134👍

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.

👤WBAR

97👍

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!

👤T.T

13👍

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.

4👍

. first step delete db.sqlite3 file
. go to terminal and run commands:

  • python manage.py makemigrations
  • python manage.py migrate
  • python manage.py createsuperuser
  • python manage.py runserver
    . go to admin page
    every thing ok now.
👤Raf

3👍

I think maybe you can try

python manage.py syncdb

Even sqlite3 need syncdb

sencondly, you can check your sql file name

it should look like xxx.s3db

3👍

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.

2👍

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.

1👍

(1) delete -> db.sqlite3
(2) your App -> migrations directory-> delete all 001_initial.py and others but dont delete __init__.py

(3) open terminal -> 
python manage.py makemigrations
python manage.py migrate 

0👍

First run: python manage.py makemigrations
Second run: python manage.py migrate

Leave a comment