As I am trying to run the this migration:
def add_user_data(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
Permission = apps.get_model(
'auth', 'Permission')
Profile = apps.get_model('user', 'Profile')
User = apps.get_model('user', 'User')
andrew_user = User.objects.create(
email='django@jambonsw.com',
password=make_password('hunter2'),
is_active=True,
is_staff=True,
is_superuser=True)
andrew_profile = Profile.objects.create(
user=andrew_user,
name='Andrew',
slug='andrew',
about='The author of this site!')
ada_user = User.objects.create(
email='ada@djangogirls.org',
password=make_password('algorhythm'),
is_active=True,
is_staff=True,
is_superuser=False)
ada_profile = Profile.objects.create(
user=ada_user,
name='Ada Lovelace',
slug='the_countess',
about=(
' '))
contributors = Group.objects.create(
name='contributors')
ada_user.groups.add(contributors)
permissions = [
'add_post',
'change_post',
]
for perm in permissions:
contributors.permissions.add(
Permission.objects.get(
codename=perm,
content_type__app_label='blog'))
def remove_user_data(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
Profile = apps.get_model('user', 'Profile')
User = apps.get_model('user', 'User')
Profile.objects.get(slug='andrew').delete()
Profile.objects.get(
slug='the_countess').delete()
User.objects.get(
email='django@jambonsw.com').delete()
User.objects.get(
email='ada@djangogirls.org').delete()
Group.objects.get(
name='contributors').delete()
class Migration(migrations.Migration):
dependencies = [
('blog', '0005_post_permissions'),
('user', '0002_profile'),
]
operations = [
migrations.RunPython(
add_user_data,
remove_user_data)
]
I ran in this error:
AttributeError: 'StateApps' object has no attribute 'label'
I don't really know what the 'StateApps' does. But As the error message states it has something to do with assigning the permissions. Can someone help? This code is from a tutorial using Django 1.8 so I think that it is django 1.11 which is making the code error.