2

I have just upgraded to Django 1.7 and I have some issues with some of my migrations. Before upgrading I used South to handle data migrations and one migration I had was to alter the field length for the name field in auth_permissions.

How can I write the same migration using django migrations >= 1.7?

Mikael
  • 3,148
  • 22
  • 20

2 Answers2

1

Is that change still required? The length of that field was a known issue for a long time, but the most recent update in the bug tracker says it was quintupled in length.

If you still want it to be even longer, you probably want this.

EDIT: Giving up on this for now. Writing a migration that is stored in app A but applied to app B involves deeper monkeying than I have time for.

Suggested routes:

  1. Use RunSQL in a migration within one of your own apps to tweak the field by hand.

  2. Fork Django 1.7.8, add the auth migration described in the comments, pip install against that github repo.

  3. Use Django 1.8, where this change is standard.

bwarren2
  • 1,347
  • 1
  • 18
  • 36
  • Not sure this was included in the 1.7.8 release. Anyway, I can't figure out how to modify the auth_permissions model using data migrations. – Mikael Jun 09 '15 at 14:55
  • Maybe something like [this](https://github.com/django/django/blob/d538e37e1b14603d1d0c94f185f378fc0ed1e53f/tests/migrations/migrations_test_apps/alter_fk/author_app/migrations/0002_alter_id.py) with a max_length change? – bwarren2 Jun 09 '15 at 15:00
  • Since the auth_permission is in a different app I can't use that. It can't manage to find the proper model. – Mikael Jun 09 '15 at 15:05
  • In a toy project as proof of concept, I was able to make it work with `python manage.py makemigrations --empty auth ` to make a file and [these](https://gist.github.com/bwarren2/8b20f3be7f281f0d388f) contents. I am still poking at writing the migration somewhere more maintainable, but it involves [overriding some inside logic](http://stackoverflow.com/questions/29575802/django-migration-file-in-an-other-app). – bwarren2 Jun 09 '15 at 15:55
  • Ah this is most likely what I need to do. Will check in the morning. Cheers! – Mikael Jun 09 '15 at 17:19
0

having problem with permission name length using Django 1.8 Python 3.4.4 (these are the latest versions that MySQL 5.6+ works with) changed the base\schema.py

in _alter_field(...)

# ********* altered - start
fragment, other_actions = self._alter_column_type_sql(table=model._meta.db_table, old_field=old_field, new_field=new_field.column, new_type=new_type)
# ******** end

changed the definition to:

def _alter_column_type_sql(self, table, old_column, column, type):

That's it. All the migration works

Tunaki
  • 132,869
  • 46
  • 340
  • 423