Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't make migrations using Postgres #35

Open
cesarmanzo opened this issue Jul 1, 2015 · 3 comments
Open

Can't make migrations using Postgres #35

cesarmanzo opened this issue Jul 1, 2015 · 3 comments
Labels

Comments

@cesarmanzo
Copy link

I noticed that if I changed the database to Postgres before doing the initial migrate, it would fail with the error

django.db.utils.ProgrammingError: relation "auth_group" does not exist

After a couple of hours I found the issue. So, I would like to suggest to add to the manual a Note that says that, if using Postgres, you need to run first:

python manage.py migrate auth

and then

python manage.py migrate

This will apply first the dependencies so that the general migration can work. If you don't run it like this, it just won't work.

Regards.

@arocks
Copy link
Owner

arocks commented Jul 3, 2015

When I experienced this problem with postgreSQL I found that changing the order of mentioning the apps (in settings.py) will solve the issue. But it seems creating the auth table explicitly works in some cases.

Would mentioning this explicitly in the docs help?

@arocks arocks added the question label Jul 3, 2015
@musicformellons
Copy link

Hello, this issue also took quite some time for me. @arocks How did you change the app order (what before what exactly). And I solved it using the migrate auth first, but now I run into the same problem when I use "python manage.py test" but with the testdatabase. @cesarmanzo So what should I do with the testdatabase, as I do not know if that can be configured at all... (if the order of apps solves the issue, then the testdatabase would not have the issue either I suppose...):
/home/bom/.pyenv/versions/my_proj3/bin/python3.4 /opt/pycharm/helpers/pycharm/django_test_manage.py test /home/bom/my_proj3/src
Testing started at 13:03 ...
Creating test database for alias 'default'...
Got an error creating the test database: database "test_my_projDB3" already exists

Type 'yes' if you would like to try deleting the test database 'test_my_projDB3', or 'no' to cancel: yes
Destroying old test database 'default'...
Traceback (most recent call last):
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "auth_group" does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/pycharm/helpers/pycharm/django_test_manage.py", line 129, in
utility.execute()
File "/opt/pycharm/helpers/pycharm/django_test_manage.py", line 104, in execute
PycharmTestCommand().run_from_argv(self.argv)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(_args, *_cmd_options)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(_args, *_options)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(_args, *_options)
File "/opt/pycharm/helpers/pycharm/django_test_manage.py", line 91, in handle
failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive, failfast=failfast, keepdb='--keepdb' in sys.argv)
File "/opt/pycharm/helpers/pycharm/django_test_runner.py", line 256, in run_tests
extra_tests=extra_tests, *_options)
File "/opt/pycharm/helpers/pycharm/django_test_runner.py", line 156, in run_tests
return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, *_kwargs)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/test/runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/test/runner.py", line 166, in setup_databases
*_kwargs
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/test/runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/db/backends/base/creation.py", line 368, in create_test_db
test_flush=not keepdb,
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/core/management/init.py", line 120, in call_command
return command.execute(_args, *_defaults)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(_args, **options)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 318, in sync_apps
cursor.execute(statement)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/db/utils.py", line 97, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/home/bom/.pyenv/versions/my_proj3/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_group" does not exist

@ethanfrey
Copy link

Here's a quick solution I found when facing the same problem, but first @arocks Thanks!!! You rock, this is a great project start and even with this one little issue saved my tons of time getting a prototype up and running.

First, the workaround:
python manage.py migrate auth; python manage.py migrate
works fine. Except my test runner will hit the same problem when running migrations. So I decided to do bit more research.

It turns out the authtools doesn't support django-1.7/1.8 migrations until the unreleased v1.3.0. So until we have that egg on pypy and can refer to it safely with migrations, we need to grab a solid commit from the github repo. I would update requirements/base.txt with the following lines:

#django-authtools>=1.3.0
-e git+https://github.com/fusionbox/django-authtools.git@8f040b9#egg=django-authtools

I did this and everything works smoothly :)

Hope you can roll this fix into the repo... Maybe tomorrow I can make a proper pull request.

kswang2400 added a commit to kswang2400/avalon that referenced this issue Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants