I recently upgraded Django to 1.8 and set up a new development database for a fresh start. Migrations and dependencies went well, safe the usual errors you get and you end up solving. The app is working locally now just fine.
However, I am getting an error when trying to run tests:
python manage.py test
This is the error I am getting:
django.db.utils.ProgrammingError: relation "auth_user" does not exist
Needless to say, Django's auth module is indeed installed and migrated in the app, so I am not sure what is going on.
Here is the full stacktrace in case you need to peek at it, but it does't say anything even remotely helpful to me to figure out the cause of this error:
Traceback (most recent call last):
File "C:/Users/dabadaba/PycharmProjects/dogpatchsports_com/mysite/manage_sched_dev.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line
utility.execute()
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 445, in execute
output = self.handle(*args, **options)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 166, in setup_databases
**kwargs
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\base\creation.py", line 368, in create_test_db
test_flush=not keepdb,
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 445, in execute
output = self.handle(*args, **options)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\migrate.py", line 318, in sync_apps
cursor.execute(statement)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\utils.py", line 98, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_user" does not exist
I can figure out a workaround following this answer which prevents the test task from running migrate
, which according to what I have been reading should be the point where the error happens. Odd enough, since when I run migrate
everything is fine.
However, I would prefer not to resort to a cheeky workaround and stick to doing things as they are designed. Additionally, this error might be a hint that something else is actually wrong and ought to be fixed.
Some solutions suggest running:
python manage.py migrate auth
python manage.py migrate
But that does nothing since there are no pending migrations in my project.
How can I solve this mysterious issue?
If you have any apps which have foreign keys to auth.User
, then make sure that the initial migrations for those apps have a dependency on the auth app:
class Migration(migrations.Migration):
dependencies = [('auth', '__first__')]
I've had the same issue and finally it solved when I've migrated one of the apps that was included in the project but which migrations does't performed automatically.
So just check your apps and then perform by hand ./manage.py makemigrations YOUR_APP_NAME
and ./manage.py migrate
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With