本文介绍了无法获取Django 1.7迁移以检测对我的数据库的正确更改。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生产Web项目运行在MySQL数据库中的数量相当的数据。我正在尝试更新一个名为enterlink的应用程序的一些更改数据库。我已经在现有的模型中创建了新的元素,并创建了新的模型。在这种迁移之前,我从来没有碰到db的架构,因为最初运行syncdb来创建它。当我运行:python manage.py makemigrations enterlink,出现以下输出(pic)。我的问题是,为什么会发生这种情况?数据库已经包括了它在图片中列出的所有模型,为什么要注册这些模型列表?当我通过执行python manage.py migrate或python manage.py migrate -fake enterlink完成迁移时,我得到一个显示的输出,但是我的数据库模式与旧的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迁移以检测对我的数据库的正确更改。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 10:37