Django testing on separate database giving "OperationalError: no such table: auth_user" Django testing on separate database giving "OperationalError: no such table: auth_user" django django

Django testing on separate database giving "OperationalError: no such table: auth_user"


run
python manage.py makemigrations <appname>
for each applications in INSTALLED_APPS.(Specially the apps that has a ForeignKey field on auth_user)

I got different error to get me here, but think cause is the same.
django.db.utils.OperationalError: (1005, "Can't create table '<test_db>.#sql-3821_1c9' (errno: 150)")

In both cases all tables related to auth module are only not created when testing, without executing makemigrations command.
I found the solution from here


What had to be done, was add these lines to manage.py:

if __name__ == "__main__":    if 'test' in sys.argv:        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.test_settings")    else:        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

After adding that if 'test' thing to main method of manage.py, the app started working correctly, after that python manage.py test and python manage.py runserver both worked with correct settings.

However, I have not got this to work with PyCharm and testing it now, how to get it to work.