Search code examples
pythondjangoherokudjango-rest-frameworkheroku-postgres

django heroku 0010_alter_group_name_max_length.py missing in 'auth' app


I'm trying to make users login with a "email - password" combo instead of "username - password" on my django website hosted on heroku

I have used this tutorial which works well on my computer (migrations included) but when i try to migrate my online installation i get an error saying that :

"django.db.migrations.exceptions.NodeNotFoundError: Migration account.0001_initial dependencies reference nonexistent parent node ('auth', '0010_alter_group_name_max_length')"

The migration file looks like that:

class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0010_alter_group_name_max_length'),
    ]

    operations = [
        migrations.CreateModel(
            name='User',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
                ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
                ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
                ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
                ('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
                ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
                ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
            ],
            options={
                'verbose_name': 'user',
                'verbose_name_plural': 'users',
                'abstract': False,
            },
            managers=[
                ('objects', account.models.UserManager()),
            ],
        ),
    ]

My ÌNSTALLED_APPS from settings.py :

# Application definition

INSTALLED_APPS = [
    #Base apps
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    #3rd party
    'rest_framework',
    'rest_framework.authtoken',

    #local apps
    'account',
    'company',
    'api',
]

As you can see, there's this line in my file which makes my migration require a migration in a auth folder (which i think is the auth folder of the django framework

('auth','0010_alter_group_name_max_length'),

On the web i found that it is an existing file in the django project git

Maybe it is caused by the django-heroku pip package that i had to install to make this project compatible with heroku servers?

I have no clue about how to make this project work. I tried removing the dependencie in the migration file but i get another error in this case:

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/related.py", line 604, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'auth.Group' cannot be resolved

Thanks for your help


Solution

  • It looks like you have a prerelease of Django installed locally, but the stable version on Heroku.

    It's a really good idea to lock your dependencies down to ensure that you're running the exact same versions everywhere. This idea is baked into specifications and tools like Pipfile, Pipenv and pip-tools, as well as popular dependency managers for other languages.

    Try running

    pip freeze > requirements.txt
    

    This should add tight versions to your dependencies, and also list indirect dependencies as well. Commit that change and push to Heroku.

    You might want to consider looking into the tools I linked above. Both Pipenv and pip-tools work fine with Heroku, the first via native support and the second by using requirements.txt as its lock file.