jazzband / django-invitations

Generic invitations app for Django
GNU General Public License v3.0
568 stars 166 forks source link

Conflicting migrations detected after 2.0.0->2.1.0 #247

Open elnygren opened 8 months ago

elnygren commented 8 months ago

After upgrading 2.0.0 -> 2.1.0

CommandError: Conflicting migrations detected
multiple leaf nodes in the migration graph: (0004_alter_invitation_id, 0004_auto_20230328_1430 in invitations).
./manage.py showmigrations

invitations
 [X] 0001_initial
 [X] 0002_auto_20151126_0426
 [X] 0003_auto_20151126_1523
 [X] 0004_alter_invitation_id
 [ ] 0004_auto_20230328_1430

Contents of 0004_alter_invitation_id

# Generated by Django 4.2.5 on 2023-11-06 23:00

from django.db import migrations, models

class Migration(migrations.Migration):
    dependencies = [
        ("invitations", "0003_auto_20151126_1523"),
    ]

    operations = [
        migrations.AlterField(
            model_name="invitation",
            name="id",
            field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
        ),
    ]

Contents of 0004_auto_20230328_1430

# Generated by Django 3.2.15 on 2023-03-28 14:30

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('invitations', '0003_auto_20151126_1523'),
    ]

    operations = [
        migrations.AlterField(
            model_name='invitation',
            name='id',
            field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
        ),
        migrations.AlterField(
            model_name='invitation',
            name='inviter',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='inviter'),
        ),
    ]
elnygren commented 8 months ago

So it seems the upgrade path for django-invitations is something like:

  1. manually rollback 0004 (manage.py migrate invitations 0003) and hope it doesn't destroy any data
  2. update to 2.1.0 (pip-sync or whatever)
  3. manage.py migrate

?

Edit:

Hmm weird, I did not have the other 0004_alter_invitation_id in prod at all but did have it in dev 🤔

stefanfeuerhahn commented 7 months ago

pip does not seem to remove the migrations when uninstalling or upgrading the django-invitations package. I therefore solved the above problem by manually deleting the migration, e.g. remove .venv/lib/python3.12/site-packages/invitations/

Flimm commented 5 months ago

I noticed that there was a missing migration file in this library, so I created it in this commit: 8ae641f In that commit, I also added a test to make sure that we don't forget to create migration files in the future.

Does this solve the issue for you?