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+):
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.
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!
- [Django]-Delete multiple objects in django
- [Django]-How to properly use the "choices" field option in Django
- [Django]-How do I use pagination with Django class based generic ListViews?
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.
- [Django]-Django: Error: You don't have permission to access that port
- [Django]-How do I create a login API using Django Rest Framework?
- [Django]-Parsing unicode input using python json.loads
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.
- [Django]-Django – Rotating File Handler stuck when file is equal to maxBytes
- [Django]-How to use UUID
- [Django]-Django TemplateSyntaxError – 'staticfiles' is not a registered tag library
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
- [Django]-Django storages aws s3 delete file from model record
- [Django]-Programmatically saving image to Django ImageField
- [Django]-Cannot set Django to work with smtp.gmail.com
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.
- [Django]-How do I migrate a model out of one django app and into a new one?
- [Django]-Migrating Django fixtures?
- [Django]-Python + Django page redirect
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.
- [Django]-Altering one query parameter in a url (Django)
- [Django]-Update django database to reflect changes in existing models
- [Django]-Django error – matching query does not exist
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
- [Django]-Catching DoesNotExist exception in a custom manager in Django
- [Django]-Authenticate by IP address in Django
- [Django]-Nginx doesn't serve static
- [Django]-Select between two dates with Django
- [Django]-How to get superuser details in Django?
- [Django]-Django celery task: Newly created model DoesNotExist