将ManyToManyField字段添加到现有模型 [英] Adding a ManyToManyField field to an existing model
问题描述
我有一个生产模型,我需要添加以下字段:
tag = models.ManyToManyField )
以下内容不会改变:
python manage.py syncdb
因此, mymodel_tag表未被创建。我正在使用Postgres。
除了删除表格并重新创建它,因为应用程序已经在生产中使用,我有什么选择。
南肯定会帮助: p>
South是为Django应用程序提供一致,易于使用和数据库无关迁移的工具。
注意,在Django 1.7(目前处于开发阶段),South将成为django的一部分( docs )。
开始的好地方是通过<一个href =http://south.readthedocs.org/en/latest/tutorial/index.html =nofollow noreferrer>教程和如何开始使用南与exi sting数据库页面。
另见:
- Django - syncdb不创建表
- < a href =https://code.djangoproject.com/ticket/2229 =nofollow noreferrer> django-admin的syncdb不检查是否丢失了多对多表
- django添加一个ManyToMany字段/表到现有模式,related_name错误
请注意,手动创建多对多表可能会像一个简单的解决方案/解决方案在短视角,但我会考虑转向南无论如何。
希望有帮助。
I have a production model and I need to add the following field to it:
tag = models.ManyToManyField(Tags)
The following is not picking up the change:
python manage.py syncdb
And therefore, mymodel_tag table is not being created. I am using Postgres.
What are my options other than dropping the table and recreating it since the application is already on production use.
解决方案South would definitely help:
South is a tool to provide consistent, easy-to-use and database-agnostic migrations for Django applications.
Note that in Django 1.7 (currently in development stage) South is going to become a part of django (docs).
A good place to start is to go through the tutorial and how to start using South with an existing database page.
Also see:
- Django - syncdb doesn't create tables
- django-admin's syncdb does not check for missing many-to-many tables
- django adding a ManyToMany field/table to existing schema, related_name error
Note that creating a many-to-many table manually may look like an easy solution/workaround in a short-perspective, but I'd consider switching to south anyway.
Hope that helps.
这篇关于将ManyToManyField字段添加到现有模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!