3

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!

Aren Li
  • 93
  • 8
  • did u run ./manage.py migrate first? – levi Nov 10 '15 at 01:08
  • Hi @levi! Thank you very much for your quick response! the doc says that "If you intend to set `AUTH_USER_MODEL`, you should set it before creating any migrations or running `manage.py migrate` for the first time." Therefore I did not run `./manage.py migrate` first. Is that something that I should have done? However, running `./manage.py migrate` would have created table for the default user model, which is not what I want. I guess my question is: how can I create a model in the first migration without also creating table for the default user? Thank you! – Aren Li Nov 10 '15 at 01:21

2 Answers2

4

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!

Aren Li
  • 93
  • 8
  • It works but you may need to delete all migration files those depend to the app you are working on. After deleting migrations run makemigrations and migrate commands. PS: I am using docker container to run my code and can delete my demo app so please be careful while deleting migrations' files for your projects in product. – Necip Asım ARSLAN Jan 19 '23 at 09:26
0

For Django 3.2 deleting the migrations directory in the users directory and running

python manage.py makemigrations users
python manage.py migrate

worked for me.