Cannot get Django 1.7 Migrations to detect proper changes to my DB.

大城市里の小女人 提交于 2019-12-06 22:50:30

What you have done is that you have ran the command python manage.py syncdb before running python manage.py makemigrations myapp and python manage.py migrate myapp. That is why syncdb created the database schema and the migration was faked because schema already exists. I will suggest to use python manage.py makemigrations myapp and python manage.py migrate myapp and not to use syncdb as its deprecated in Django 1.7.

If you change anything in your model, just run makemigrations and migrate command. Syncdb isn't necessary.

This question and relevant answers are intriguing me. Thus I want to share my experience on maintaining live database and migrations.

Tested in django1.5.5

Initializing the database:

  1. ./manage.py syncdb --noinput
  2. ./manage.py migrate
  3. ./manage.py syncdb

Now I have created the database.

Doing a migration for an app:

  1. ./manage.py schemamigration myapp --initial
  2. ./manage.py migrate myapp --fake
  3. Now do necessary changes in your model
  4. ./manage.py schemamigration myapp --auto
  5. ./manage.py migrate myapp

Im newbie for schemamigration too, but i will explain how it works for me:

First you create app and then ./manage.py sycndb, so tables are created then you can ./manage.py makemigrations myapp --initial so now initial migrations are created and you should apply them ./manage.py migrate myapp now you can change your models : add,change fields, anything you want and then ./manage.py makemigrations myapp --auto this will create migrations for changes and now you need to apply them enter code here./manage.py migrate myapp so this actually will create new tables in db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!