django手写迁移改变auth [英] django handwritten migrations altering auth

查看:165
本文介绍了django手写迁移改变auth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django 1.8.1,并尝试从我的一个应用程序扩展auth_user名称字段的长度。以前,南方我可以用下划线来定位应用程序,如下所示:

  db.alter_column('auth_group',' name',models.CharField(max_length = 120,null = False,blank = False))

,在django 1.8中,我没有看到这样做,因为django将sql中的应用程序名称放在源代码中。我不想编辑django源代码,所以我没办法改变。我目前的attemp在这里:

  class Migration(migrations.Migration):

dependencies = [
('auth','0006_require_contenttypes_0002'),
]

operations = [
migrations.AlterField('auth_group','name',field = models.CharField (max_length = 120,null = False,blank = False)),
]

请帮帮我。我不想编辑django源代码,我只想做migrations.RunSQL作为最后的手段。

解决方案

谢谢@Ernest十。



在我的情况下,我保持依赖:


依赖关系= [
#指定其他依赖关系,如果需要。
('auth','0004_alter_user_username_opts')
]




确保运行python manage.py migrate得到这个反映给你的数据库。


I am using django 1.8.1 and trying to extend the length of auth_user name field from one of my apps. Before, with south, I could just target the app with an underscore like so:

db.alter_column('auth_group', 'name', models.CharField(max_length=120, null=False, blank=False))

However, in django 1.8, I don't see a way to do this as django putts the app name in the sql withing the source code. I don't want to edit django source code so I have no way of changing that. my current attemp is here:

class Migration(migrations.Migration):

dependencies = [
    ('auth', '0006_require_contenttypes_0002'),
]       

operations = [
    migrations.AlterField('auth_group', 'name', field=models.CharField(max_length=120, null=False, blank=False)),
]

Please help. I don't want to edit django source code and I only want to do migrations.RunSQL as a last resort.

解决方案

Thanks @Ernest Ten.

In my case, I kept the dependency on:

dependencies = [ # Specify other dependencies, if required. ('auth', '0004_alter_user_username_opts') ]

Make sure you run "python manage.py migrate" to get this reflected to you db.

这篇关于django手写迁移改变auth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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