Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name of order field in migrations #60

Closed
TyVik opened this issue Aug 23, 2015 · 6 comments
Closed

Name of order field in migrations #60

TyVik opened this issue Aug 23, 2015 · 6 comments

Comments

@TyVik
Copy link

TyVik commented Aug 23, 2015

Problem IMHO in migrations of Django 1.7 (not South). I use custom field name for order field in M2M:

attributes = SortedManyToManyField(Attribute, sort_value_field_name='order')

then make migration and apply it. After which in db was created M2M table with default field name ('sort_value') instead my overriding name ('order').

@gregmuellegger
Copy link
Collaborator

Yes, that might be bug. True, I've never tested for this case. I would suggest adding the sort_value_field_name='order' also to the generated migration, so that it reads:

field=sortedm2m.fields.SortedManyToManyField(to='...', sort_value_field_name='order'),

I would be interested in your tests and if the approach I suggest here is working well for your case.

@TyVik
Copy link
Author

TyVik commented Sep 1, 2015

I add sort_value_field_name='order' but this no effect:

        migrations.AddField(
            model_name='attribute',
            name='settings',
            field=sortedm2m.fields.SortedManyToManyField(related_name='sce',  to='scenario.Setting', sort_value_field_name='order'),
            preserve_default=False,
        ),

Maybe because Django migration create object for migrate with default parameters. But I see next code in https://github.com/django/django/blob/master/django%2Fdb%2Fmigrations%2Foperations%2Ffields.py#L43:

    def state_forwards(self, app_label, state):
        # If preserve default is off, don't use the default for future state
        if not self.preserve_default:
            field = self.field.clone()
            field.default = NOT_PROVIDED
        else:
            field = self.field
...

Error in django?

@gregmuellegger
Copy link
Collaborator

Hm, not sure. I'm not sure were the problem might be currently. However that's not really one of my priorities so far.

Would you be willing to find the cause of the issue and try to fix it? I'm happy to review any pull requests and assist with questions about sortedm2m internals.

@TyVik
Copy link
Author

TyVik commented Sep 1, 2015

Unfortunately, I closed this project, but bug is so strange... I try to create pull request during next month.

@TyVik
Copy link
Author

TyVik commented Sep 10, 2015

I checked on Django 1.8 and all fine! In migration:

        migrations.AddField(
            model_name='book',
            name='authors',
            field=sortedm2m.fields.SortedManyToManyField(help_text=None, to='m2m.Author', sort_value_field_name=b'order'),
        ),

And after applied it in db created table with field 'order'. I`m sorry for bad issue :(

@TyVik TyVik closed this as completed Sep 10, 2015
@gregmuellegger
Copy link
Collaborator

Cool, glad that it worked out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants