将ManyToManyField字段添加到现有模型 [英] Adding a ManyToManyField field to an existing model

查看:169
本文介绍了将ManyToManyField字段添加到现有模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生产模型,我需要添加以下字段:

  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数据库页面。



另见:





请注意,手动创建多对多表可能会像一个简单的解决方案/解决方案在短视角,但我会考虑转向南无论如何。



希望有帮助。


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:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆