Skip to content

Conversation

@AlejandroRivera
Copy link

With --run-sync-db:

$ sudo PYTHONPATH=/opt/graphite/webapp django-admin.py migrate --settings=graphite.settings --run-syncdb
Operations to perform:
  Synchronize unmigrated apps: account, render, staticfiles, whitelist, metrics, url_shortener, dashboard, composer, events, browser
  Apply all migrations: admin, contenttypes, tagging, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
    Creating table account_profile
    Creating table account_variable
    Creating table account_view
    Creating table account_window
    Creating table account_mygraph
    Creating table dashboard_dashboard
    Creating table dashboard_template
    Creating table events_event
    Creating table url_shortener_link
    Running deferred SQL...
Traceback (most recent call last):
  File "/usr/local/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 172, in handle
    self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 293, in sync_apps
    cursor.execute(statement)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/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

Without --run-sync-db:

$ sudo PYTHONPATH=/opt/graphite/webapp django-admin.py migrate --settings=graphite.settings
Operations to perform:
  Apply all migrations: admin, contenttypes, tagging, auth, sessions
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying sessions.0001_initial... OK
  Applying tagging.0001_initial... OK
  Applying tagging.0002_on_delete... OK

@deniszh
Copy link
Member

deniszh commented Nov 25, 2017

I think you need to run
PYTHONPATH=$GRAPHITE_ROOT/webapp django-admin.py migrate auth --settings=graphite.settings
first - it will create auth relations, then --run-syncdb will work well.

@AlejandroRivera
Copy link
Author

When i tried it myself without auth (and without --run-syncdb) it seemed to have created all the tables (including auth relations), since when i tried --run-syncdb right after, there were no issues.

At this point, i'm not sure what's the difference between:

PYTHONPATH=$GRAPHITE_ROOT/webapp django-admin.py migrate auth --settings=graphite.settings

and

PYTHONPATH=$GRAPHITE_ROOT/webapp django-admin.py migrate --settings=graphite.settings

but if you say that's the right way of creating the DB for the first time, i can make the change in the PR. I'll await confirmation.

@deniszh
Copy link
Member

deniszh commented Nov 26, 2017

Well... I'm not a big Django expert, unfortunately. If migrate doing the same as migrate auth and migrate --run-syncdb then it's simpler - because it's a single command.
Maybe @brutasse knows?

@codecov-io
Copy link

Codecov Report

Merging #2126 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2126   +/-   ##
=======================================
  Coverage   77.63%   77.63%           
=======================================
  Files          79       79           
  Lines        8195     8195           
  Branches     1684     1684           
=======================================
  Hits         6362     6362           
  Misses       1575     1575           
  Partials      258      258

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b73cc91...3ea588f. Read the comment docs.

@deniszh
Copy link
Member

deniszh commented Dec 4, 2017

I spent some time with python3 and django 1.11. Looks like migrate auth and migrate behaves little better.

@AlejandroRivera
Copy link
Author

AlejandroRivera commented Dec 4, 2017

Looks like migrate auth and migrate behaves little better.

Sorry, i'm not sure i understand what you mean. Can you elaborate?

@deniszh
Copy link
Member

deniszh commented Dec 4, 2017

@AlejandroRivera:
No, disregard that. What's your Django version?
Looks like migrate auth and migrate --run-syncdb works fine for 1.8.x, but cause troubles for 1.11

@AlejandroRivera
Copy link
Author

My version is 1.9.13

@deniszh deniszh added the bug label Jan 14, 2018
@deniszh
Copy link
Member

deniszh commented Jan 14, 2018

TBH I didn't reproduce cases when --run-sync-db doesn't work, but simple migrate does. I'll prefer to keep --run-sync-db in documentation, because it works well on empty db, but upgrade manual is still open question.

@AlejandroRivera
Copy link
Author

@deniszh, do you have any ideas of who to tag so the discussion can take place? I do not :(

@DanCech
Copy link
Member

DanCech commented Jan 15, 2018

I suspect the correct command varies by django version :( I'll do some digging and see what I can find out

@ploxiln
Copy link
Contributor

ploxiln commented Mar 1, 2020

This can be closed because #2425 was merged

@piotr1212 piotr1212 closed this Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants