Skip to content

Setting user_related_name results in strange migrations in v2.6.0 #520

Closed
@dgilge

Description

@dgilge

Describe the bug

  1. Setting user_related_name="mymodels" doesn't change related_name="+" to related_name="mymodels" since v2.6.0.
  2. Setting user_related_name="mymodels" shouldn't alter other values in migrations

To Reproduce

  1. Install v2.5.1
  2. Add a history to a model, e.g. with register:
register(
    EmailAddress,
    app=__package__,
    excluded_fields=('primary',),
    user_related_name='historicalemailaddresses',
)
  1. Run makemigrations
  2. Install v2.6.0
  3. Run makemigrations
  4. Remove user_related_name
  5. Run makemigrations

Expected behavior

  1. No. 5 shouldn't create another migration with related_name="+"
  2. No. 7 should change related_name="+" only (but it doesn't because it has this value in the previous migration already). But the change looks like this on my system:

After applying No. 5:

        migrations.AlterField(
            model_name="historicalemailaddress",
            name="user",
            field=models.ForeignKey(
                blank=True,
                db_constraint=False,
                null=True,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="+",
                to=settings.AUTH_USER_MODEL,
                verbose_name="user",
            ),
        )

Why were blank, db_constraint and verbose_name (and other values like help_text in other cases) added here?

After applying No. 7:

        migrations.AlterField(
            model_name="historicalemailaddress",
            name="history_user",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="+",
                to=settings.AUTH_USER_MODEL,
            ),
        )

The migration in < v2.6.0 looked like (I comment strange changes):

        migrations.AlterField(
            model_name="historicalemailaddress",
            name="history_user",  # Why this changed to "user"?
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,  # Why this changed to "DO_NOTHING"?
                related_name="historicalemailaddresses",
                to=settings.AUTH_USER_MODEL,
            ),
        )

Environment:

  • OS: macOS 10.13.6
  • Django Simple History Version: 2.6.0, 2.7.0
  • Django Version: 2.0.10
  • Database Version: PostgreSQL 9.6

I also want to say "thank you" for all the improvements and fixes you implemented in the last months for simple history and for keeping this package alive!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions