2013-08-20 2 views
0

IS il y a une option pour mettre à jour un nouveau champ avec le modèle existant dans django 1.4.J'ai des noms de cours de personne ayant des champs "name", "dob", "age" dans models.py . Maintenant, je veux ajouter un nouveau champ "emplacement" dans la classe. Comment synchroniser ce nouveau champ dans la table existante.Django comment migrer de nouveaux modèles avec le modèle existant

+0

avez-vous obtenu une solution à votre problème? – drabo2005

+0

@ abda2005 Non, vous suggérez à dbshell que c'est un processus manuel. Chaque fois que je veux modifier la table si je fais des changements dans le modèle. vous avez une autre idée – user

Répondre

3

vous pouvez utiliser un plugin comme south pour atteindre cet

+0

J'utilise Django 1.4 si le sud fonctionne dans cette version. – user

+0

oui cela fonctionne avec Django 1.4 vérifier ce [link] (http://south.readthedocs.org/en/latest/releasenotes/0.7.4.html) pour référence – amdorra

1

une manière très simple de le faire sans migration vers le sud.

first add the field name in your model and get under the shell type 

$ python manage.py dbshell 

you will get directly within your database shell (mysql or psql) it up to what database 
you are using. 

mysql> | psql> ALTER TABLE <table_name> ADD column varchar(100); 

and it will add the new column to your table, doesn't matter if the table it already 
    populated or not. 

$ python manage.py syncdb 

et qu'il vous est bon

Questions connexes