无法获取Django 1.7迁移以检测对我的数据库的正确更改。 [英] Cannot get Django 1.7 Migrations to detect proper changes to my DB.
问题描述
你所做的是你运行的命令 python manage.py syncdb
之前运行 python manage.py makemigrations myapp
和 python manage.py migrate myapp
。这就是为什么 syncdb
创建了数据库模式,并且迁移被伪造,因为模式已经存在。我会建议使用 python manage.py makemigrations myapp
和 python manage.py migrate myapp
而不使用 syncdb
在Django 1.7中已被弃用。
如果您更改模型中的任何内容,只需运行 makemigrations
和迁移
命令。 Syncdb不是必需的。
I have a production web project running with a decent amount of data in the MySQL db. I am trying to update the database with some changes to an app called "enterlink." I've made new elements in the existing models and created new models altogether. Before this migration, I have never touched the schema of the db since originally running syncdb to create it. When I run: "python manage.py makemigrations enterlink" the below output appears(pic). My question is, why is this happening? The DB already includes all the models that it lists in the picture so why is it registering those lists of models? When I go to finish the migration by doing "python manage.py migrate" or "python manage.py migrate --fake enterlink" (pic again), I get an output shown but my database schema remains identical to the old db and any new code generates errors. Can anyone tell me what is likely the problem? I would be really appreciative of any advice. It's been very frustrating since I'm not sure what I'm missing.
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.
这篇关于无法获取Django 1.7迁移以检测对我的数据库的正确更改。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!