lazy reference: doesn't provide model user?

后端 未结 9 1326
独厮守ぢ
独厮守ぢ 2020-12-15 06:33

Currently I\'m using Django 1.11 and Python 3.6. I\'m attempting to create a custom user model with a new application that authenticates with LDAP, but i\'m greeted with th

9条回答
  •  囚心锁ツ
    2020-12-15 06:59

    This is caused by your settings.AUTH_USER_MODEL having changed to a model that does not exist when migrations are being computed.

    A slightly hacky way to fix this without data loss, if you're migrating from auth.User to custom.User is to add a "virtual" (separate database and state) minimal model (that is, only the ID field, to allow for foreign keys) according to the new User model in the very initial migration, so future migrations have this reference:

    operations=[
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.CreateModel(
                    name="User",
                    fields=[
                        (
                            "id",
                            models.AutoField(
                                auto_created=True,
                                primary_key=True,
                                serialize=False,
                                verbose_name="ID",
                            ),
                        )
                    ],
                    options={"db_table": "auth_user"},
                    managers=[("objects", UserManager())],
                )
            ]
        ),
        # ... other migrations
    

提交回复
热议问题