Migrations in Django 1.7

不羁岁月 提交于 2019-12-05 02:12:42

问题


I am currently involved in a project where I am using Django 1.7 development version.I want to propogate changes that I make in my models (adding a field, deleting a model, etc.) into the database schema using "makemigrations" and "migrate" commmands.I added a "age" field to one of the models in my application.

country = models.CharField(max_length=50, blank=True)
address = models.CharField(max_length=100, blank=True)
postal_code = models.IntegerField(max_length=50, blank=True)
city = models.CharField(max_length=50, blank=True)
phone_no = models.CharField(max_length=25, blank=True)
skype_name = models.CharField('Skype Username',max_length=50, blank=True)
age=models.IntegerField(max_length=25,blank=True)

When I use "makemigrations" command ,the output is like---"No changes detected".I guess that "makemigrations" is not able to figure out the changes made to the schema.Any suggestions how can I make it work??


回答1:


If you are adding initial migrations to an app, you must include the app name when using the makemigrations command.

python manage.py makemigrations your_app_label



回答2:


If it is the first time you are migrating that app you have to use:

manage.py makemigrations myappname

Once you do that you can do:

manage.py migrate

If you had your app in database, modified its model and its not updating the changes on makemigrations you probably havent migrated it yet. Change your model back to its original form, run the first command (with the app name) and migrate...it will fake it. Once you do that put back the changes on your model, run makemigrations and migrate again and it should work.




回答3:


I have sometimes the same problem. I manage to populate the change in the database by following :

rm -rf your_app/migrations/*

python manage.py migrate

if it doesn't work, consider a manual drop table before, if you don't have data in it.

it worked for me with django 1.7c1



来源:https://stackoverflow.com/questions/23068275/migrations-in-django-1-7

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