django no such table:
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):
- Grab any SQLite GUI tool (i.e. http://sqliteadmin.orbmu2k.de/)
- Change your model definition to match database definition (best approach is to comment new fields)
- Delete
migrations
folder in your model- Delete rows in
south_migrationhistory
table whereapp_name
match your application name (probablyhomework
)- Invoke:
./manage.py schemamigration <app_name> --initial
- Create tables by
./manage.py migrate <app_name> --fake
(--fake
will skip SQL execute because table already exists in your database)- Make changes to your app's model
- Invoke
./manage.py schemamigration <app_name> --auto
- Then apply changes to database:
./manage.py migrate <app_name>
Steps 7,8,9 repeat whenever your model needs any changes.
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!
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.
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.
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.