pythondjangodjango-authenticationdjango-usersdjango-custom-user

Django: when creating custom user, ValueError: Dependency on unknown app


I'm building a brand-new web project with Python 3.4.3 and Django 1.8 without any migrations made so far. For the project, I'm creating a custom user inheriting from AbstractBaseUser in an app called users. I've also correctly referred AUTH_USER_MODEL to the custom user in settings.py, before creating any migrations, as mentioned in the doc.

However, when I tried to run python manage.py makemigrations users or python manage.py migrate, the console reports ValueError: Dependency on unknown app: users.

I'm pretty sure my code for the custom user model is correct because I followed documentation's example code, and also because, when I commented out AUTH_USER_MODEL, everything else worked fine except that Django created tables for the default User model, which is expected.

In the documentation it is mentioned that:

you must ensure that the model referenced by AUTH_USER_MODEL is created in the first migration of its app (usually called 0001_initial); otherwise, you will have dependency issues.

I'm not very sure what exactly this means. Does it mean that I have to manually create a migration for my users app? If so, how exactly should I do it?

I greatly appreciate any suggestion or redirection to a credible source! Thank you very much in advance!


Solution

  • So after trying various approaches to tackle the problem, I found that the problem lie in an accidental mistake. In the users directory, I've deleted all the files in migrations directory including its __init__.py. If there is no __init__.py file, the ValueError will be thrown. If you manually add the __init__.py file, everything works like a charm.

    To those having the same problem, good luck!