pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.51k stars 3.03k forks source link

Django 1.7 migrations are out of sync with models #836

Closed jessamynsmith closed 9 years ago

jessamynsmith commented 9 years ago

In a clean Django 1.7 project, if I add allauth.socialaccount to INSTALLED_APPS, I get an error on python manage.py migrate:

Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

If I run python manage.py makemigrations it generates a migration for socialaccount:

Migrations for 'socialaccount':
    0002_auto_20150214_0523.py:
        - Alter field extra_data on socialaccount
        - Alter field provider on socialaccount
        - Alter field provider on socialapp
jelenak commented 9 years ago

The same error.

ben519 commented 9 years ago

Same

cmdelatorre commented 9 years ago

Same here. Besides, every time I execute

manage.py makemigrations && PYTHONPATH=~/dev/aimara/ ./manage.py migrate

A new migration is created:

Migrations for 'socialaccount': 0009_auto_20150223_1658.py:

  • Alter field provider on socialaccount
  • Alter field provider on socialapp Operations to perform: Synchronize unmigrated apps: pipeline, allauth, github, google Apply all migrations: socialaccount, sessions, account, sites, admin, contenttypes, auth... Synchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes... Running migrations: Applying socialaccount.0009_auto_20150223_1658... OK

Examples of successive generated migrations here.

The change between migrations is just the order of the arguments given to models.CharField(...), in migrations.AlterField(... field=models.CharField(...))

jessamynsmith commented 9 years ago

I looked into this a little more. The change on extra_data seems to be just the b'' vs '' on the default, from:

('extra_data', allauth.socialaccount.fields.JSONField(default=b'{}', verbose_name='extra data')),

to

('extra_data', allauth.socialaccount.fields.JSONField(default='{}', verbose_name='extra data')),
migrations.AlterField(
            model_name='socialaccount',
            name='extra_data',
            field=allauth.socialaccount.fields.JSONField(default='{}', verbose_name='extra data'),
            preserve_default=True,
        ),

For socialaccount and socialapp, it is a change in choices for provider, presumably related to the dynamically generated choices. In models.py:

provider = models.CharField(verbose_name=_('provider'),
                                max_length=30,
                                choices=providers.registry.as_choices())

Because I only have facebook enabled, the generated migration has:

        migrations.AlterField(
            model_name='socialaccount',
            name='provider',
            field=models.CharField(verbose_name='provider', max_length=30, choices=[('facebook', 'Facebook')]),
            preserve_default=True,
        ),
        migrations.AlterField(
            model_name='socialapp',
            name='provider',
            field=models.CharField(verbose_name='provider', max_length=30, choices=[('facebook', 'Facebook')]),
            preserve_default=True,
        ),
briandant commented 9 years ago

I opened a PR that fixes some of these migration issues.

https://github.com/pennersr/django-allauth/pull/863