django handwritten migrations altering auth -
i using django 1.8.1 , trying extend length of auth_user name field 1 of apps. before, south, target app underscore so:
db.alter_column('auth_group', 'name', models.charfield(max_length=120, null=false, blank=false)) however, in django 1.8, don't see way django putts app name in sql withing source code. don't want edit django source code have no way of changing that. current attemp 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. don't want edit django source code , want migrations.runsql last resort.
well, there tricky way that:
# -*- coding: utf-8 -*- django.db.migrations import migration djangomigration, alterfield django.db.models import charfield class migration(djangomigration): dependencies = [ # specify other dependencies, if required. ('auth', '0006_require_contenttypes_0002') ] operations = [ alterfield( model_name='user', name='username', field=charfield(max_length=120) ) ] def mutate_state(self, project_state, preserve=true): """ workaround allows store ``auth`` migration outside directory should stored. """ app_label = self.app_label self.app_label = 'auth' state = super(migration, self).mutate_state(project_state, preserve) self.app_label = app_label return state def apply(self, project_state, schema_editor, collect_sql=false): """ same workaround described in ``mutate_state`` method. """ app_label = self.app_label self.app_label = 'auth' state = super(migration, self).apply(project_state, schema_editor, collect_sql) self.app_label = app_label return state put in application's migrations folder proper name, e.g. 0001_alter_auth_user_username.py.
i'm not sure, however, approach.
Comments
Post a Comment