Django 1.6编辑userprofile模型与现有用户 [英] Django 1.6 editing userprofile model with existing users

查看:92
本文介绍了Django 1.6编辑userprofile模型与现有用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个django数据库,其中包含用户模型的自定义用户配置文件。
问题是,当我想要添加新的字段到我的userprofile类,我得到错误没有这样的列,关于新的字段,当尝试访问用户表。



任何方式然后更新userprofile模型,而不必重建数据库?



谢谢

解决方案

这是怎么做的..



首先安装 south

  pip install south 

然后添加到您的设置 INSTALLED_APP 列表为 -

  ...,
'south',
...

什么是南方?南方是一个django应用程序,可帮助您更新数据库,而无需重新构建。现在用 -



初始化你的模型python manage.py syncdb //这将创建迁移的南表
python manage.py schemamigration< appname> - 初始//(每应用一次),这将在迁移包中创建初始模型文件
python manage.py migrate

然后每次更新您的模型只需要执行一个更新 -

  python管理.py schemamigration< appname> --auto 
python manage.py migrate< appname>

您可以在这里找到完整的文档 - http://south.readthedocs.org/en/latest/tutorial/


I have a django database with a custom user profile for the user model. The problem is that when I want to add new fields to my userprofile class, I get the error no such column, regarding the new field, when trying to access the users table.

Any way then to update the userprofile model without having to rebuild the database?

Thank you.

解决方案

Here is how to do it..

First install south

pip install south

Then add to your settings INSTALLED_APP list as -

   ...,
   'south',
   ...

What is south?.. Well south is a django app that helps you updating your database without having to rebuild it. Now initialise your models with-

python manage.py syncdb // this will create the south tables for migrations
python manage.py schemamigration <appname> --initial //  (once per app) this will create the initial model files in a migrations package
python manage.py migrate

Then every time you update your models just need to perform an update with -

python manage.py schemamigration <appname> --auto
python manage.py migrate <appname>

You can find the full documentation here - http://south.readthedocs.org/en/latest/tutorial/

这篇关于Django 1.6编辑userprofile模型与现有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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