Thanks to visit codestin.com
Credit goes to github.com

Skip to content

invoke migrate is needed prior to invoke createsuperuser for a fresh dev install #600

@tim-fiola

Description

@tim-fiola

Environment

  • Python version: 3.6
  • Nautobot version: 1.0.2

Steps to Reproduce

  1. Using the Docker Compose Workflow for a fresh dev environment
  2. Starting here: https://nautobot.readthedocs.io/en/latest/development/getting-started/#using-docker-with-invoke
  3. attempt invoke createsuperuser

Expected Behavior

A superuser to successfully be created

Observed Behavior

nautobot_blog/nautobot % invoke createsuperuser                                                                                                                              (tim-fiola-doc-blog)nautobot
Running docker-compose command "ps --services --filter status=running"
Running docker-compose command "run --entrypoint 'nautobot-server createsuperuser --username admin' nautobot"
Creating nautobot_nautobot_run ... done
19:37:26.210 WARNING nautobot.extras.apps apps.py                                  ready() :
  Wrapping model clean methods for custom validators failed because the ContentType table was not available or populated. This is normal during the execution of the migration command for the first time.

You have 49 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, circuits, contenttypes, dcim, extras, ipam, sessions, social_django, taggit, tenancy, users, virtualization.
Run 'python manage.py migrate' to apply them.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "auth_user" does not exist
LINE 1: ... "auth_user"."id", "auth_user"."config_data" FROM "auth_user...
                                                             ^


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

Traceback (most recent call last):
  File "/usr/local/bin/nautobot-server", line 5, in <module>
    main()
  File "/source/nautobot/core/cli.py", line 62, in main
    initializer=_configure_settings,  # Called after defaults
  File "/source/nautobot/core/runner/runner.py", line 266, in run_app
    management.execute_from_command_line([runner_name, command] + command_args)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
    return super().execute(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 102, in handle
    error_msg = self._validate_username(username, verbose_field_name, database)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 234, in _validate_username
    self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 45, in get_by_natural_key
    return self.get(**{self.model.USERNAME_FIELD: username})
  File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/cacheops/query.py", line 353, in get
    return qs._no_monkey.get(qs, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 425, in get
    num = len(clone)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 269, in __len__
    self._fetch_all()
  File "/usr/local/lib/python3.6/site-packages/cacheops/query.py", line 283, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/cacheops/transaction.py", line 93, in execute
    result = self._no_monkey.execute(self, sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "auth_user" does not exist
LINE 1: ... "auth_user"."id", "auth_user"."config_data" FROM "auth_user...
                                                             ^

ERROR: 1
nautobot_blog/nautobot % 

Corrective Step

For a fresh dev install in this pipeline, it looks like a invoke migrate is required:

nautobot_blog/nautobot % invoke migrate                                                                                                                                      (tim-fiola-doc-blog)nautobot
Running docker-compose command "ps --services --filter status=running"
Running docker-compose command "run --entrypoint 'nautobot-server migrate' nautobot"
Creating nautobot_nautobot_run ... done
19:38:08.623 WARNING nautobot.extras.apps apps.py                                  ready() :
  Wrapping model clean methods for custom validators failed because the ContentType table was not available or populated. This is normal during the execution of the migration command for the first time.
<----- snip ----->
nautobot_blog/nautobot %                                                                                                                                                     (tim-fiola-doc-blog)nautobot
nautobot_blog/nautobot % invoke createsuperuser                                                                                                                              (tim-fiola-doc-blog)nautobot
Running docker-compose command "ps --services --filter status=running"
Running docker-compose command "run --entrypoint 'nautobot-server createsuperuser --username admin' nautobot"
Creating nautobot_nautobot_run ... done
Email address: 
Password: 
Password (again): 
Superuser created successfully.
nautobot_blog/nautobot %                      

The superuser creates successfully after the invoke migrate

I'll submit a PR to fix the docs if that's ok

Metadata

Metadata

Assignees

Labels

type: bugSomething isn't working as expectedtype: documentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions