# Create default model permissions before running application migrations

**URL:** <https://forum.djangoproject.com/t/create-default-model-permissions-before-running-application-migrations/31747>\
**Category:** Django Internals\
**Created:** [June 4, 2024, 5:30pm UTC](https://forum.djangoproject.com/t/create-default-model-permissions-before-running-application-migrations/31747 "2024-06-04T17:30:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![braiam](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/braiam/32/12549_2.png) [@braiam](https://forum.djangoproject.com/u/braiam)\
**Post date:** [June 4, 2024, 5:30pm UTC](https://forum.djangoproject.com/t/create-default-model-permissions-before-running-application-migrations/31747/1 "2024-06-04T17:30:59Z")

</div>

I’m trying to create users using datamigrations on a new project. None of the default permissions are being created for the User model (nor any other model). If I skip setting that user with those permissions or do it after I already ran migration, it would work.

I don’t think this is a desired behavior. If data migrations are being run, it should do after dependency application data is already in.

How to reproduce:

1. Create an empty project

2. Create an app “test”

3. Create an initial empty migration file `./manage.py makemigration test --empty`

4. Add the following content for “test/migrations/0001\_initial.py”:

5. Run `./manage.py migrate`

**If you ran migrate before you created the data migration, it will work.** If the application is deployed on the field, it will fail deployment.

---

<div class="post-metadata">

**Author:** ![charettes](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/charettes/32/27_2.png) [@charettes](https://forum.djangoproject.com/u/charettes)\
**Post date:** [June 4, 2024, 8:45pm UTC](https://forum.djangoproject.com/t/create-default-model-permissions-before-running-application-migrations/31747/2 "2024-06-04T20:45:46Z")

</div>

You are running into [#29843](https://code.djangoproject.com/ticket/29843).

A workaround might be to use `Permission.objects.get_or_create` instead or to call `django.contrib.auth.management.create_permissions` manually prior to doing `Permission.objects.get` instead by passing `(apps.get_app_config('auth'), using=schema_editor.connection.alias, apps=apps)`.
