Unable to run 'python manage.py migrate' for netbox 2.7.x

246 views
Skip to first unread message

Austin English

unread,
Apr 17, 2020, 1:43:19 AM4/17/20
to NetBox
I originally opened a ticket upstream (https://github.com/netbox-community/netbox/issues/4447), which was closed because I had run 'upgrade.sh' instead of 'migrate.py'. The same error occurs with migrate.py (which is unsurprising, given that upgrade.sh does the same).

```
+ python3.6 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... 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 auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying taggit.0001_initial... OK
  Applying taggit.0002_auto_20150616_2121... OK
  Applying tenancy.0001_initial_squashed_0005_change_logging... OK
  Applying dcim.0001_initial... OK
  Applying ipam.0001_initial... OK
  Applying dcim.0002_auto_20160622_1821... OK
  Applying extras.0001_initial_squashed_0013_objectchange... OK
  Applying ipam.0002_vrf_add_enforce_unique... OK
  Applying dcim.0003_auto_20160628_1721_squashed_0010_devicebay_installed_device_set_null... OK
  Applying ipam.0003_ipam_add_vlangroups_squashed_0011_rir_add_is_private... OK
  Applying dcim.0011_devicetype_part_number_squashed_0022_color_names_to_rgb... OK
  Applying ipam.0012_services_squashed_0018_remove_service_uniqueness_constraint... OK                                                                                                       
  Applying dcim.0023_devicetype_comments_squashed_0043_device_component_name_lengths... OK
  Applying virtualization.0001_virtualization... OK                                                                                                                                          
  Applying ipam.0019_virtualization_squashed_0020_ipaddress_add_role_carp... OK
  Applying dcim.0044_virtualization_squashed_0061_platform_napalm_args... OK                                                                                                                 
  Applying extras.0014_configcontexts_squashed_0019_tag_taggeditem... OK
  Applying dcim.0062_interface_mtu_squashed_0065_front_rear_ports... OK                                                                                                                      
  Applying circuits.0001_initial_squashed_0006_terminations... OK
  Applying dcim.0066_cables...                                                                                                                                                               
    Adding console connections... 0 cables created
    Adding power connections... 0 cables created                                                                                                                                             
    Adding interface connections... 0 cables created  
 OK                                                                                                                                                                                          
  Applying circuits.0007_circuit_add_description_squashed_0017_circuittype_description...
    Adding circuit terminations... 0 cables created                                                                                                                                          
Traceback (most recent call last):                                                            
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django_prometheus/db/common.py", line 67, in execute
    return super(CursorWrapper, self).execute(*args, **kwargs)
psycopg2.errors.UndefinedFunction: operator does not exist: character varying >= integer                                                                                                     
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
                                                                                                                                                                                             
                                                                                              
The above exception was the direct cause of the following exception:                  

Traceback (most recent call last):            
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/base/schema.py", line 535, in alter_field
    old_db_params, new_db_params, strict)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/postgresql/schema.py", line 124, in _alter_field
    new_db_params, strict,
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/base/schema.py", line 685, in _alter_field
    params,
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/base/schema.py", line 137, in execute
    cursor.execute(sql, params)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/cacheops/transaction.py", line 99, in execute
    result = self._no_monkey.execute(self, sql, params)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/netbox/venv/lib64/python3.6/site-packages/django_prometheus/db/common.py", line 67, in execute
    return super(CursorWrapper, self).execute(*args, **kwargs)
django.db.utils.ProgrammingError: operator does not exist: character varying >= integer
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
```

Looking through the archives, I found some similar references:
https://groups.google.com/forum/#!searchin/netbox-discuss/operator$20does$20not$20exist|sort:date/netbox-discuss/w67-u3RgX8k/EtvX2sghEwAJ
https://groups.google.com/forum/#!searchin/netbox-discuss/operator$20does$20not$20exist|sort:date/netbox-discuss/VyqU1kfweIc/gyljwvTgAAAJ

each suggests dropping some constraints, e.g.,: `alter table circuits_circuit drop constraint  "circuits_circuit_status_check";`

but that doesn't seem to work for me:
```
+ psql -U postgres -c 'ALTER TABLE circuits_circuit DROP CONSTRAINT circuits_circuit_status_check;'
ERROR:  relation "circuits_circuit" does not exist
```

I've tried 2.7.6/2.7.8/2.7.11/2.7.12, seeing the same results each time. Does anyone have any other suggestions?

Brian Candler

unread,
Apr 17, 2020, 3:10:50 AM4/17/20
to NetBox
You need to supply "netbox" as the dbname argument, otherwise it connects to the default ("root") database.

root@netbox:~# sudo -u postgres psql -c 'select count(*) from circuits_circuit'
could not change directory to "/root": Permission denied
ERROR:  relation "circuits_circuit" does not exist
LINE 1: select count(*) from circuits_circuit
                             ^
root@netbox:~# sudo -u postgres psql -c 'select count(*) from circuits_circuit' netbox
could not change directory to "/root": Permission denied
 count
-------
     2
(1 row)

Austin English

unread,
Apr 17, 2020, 7:45:39 PM4/17/20
to Brian Candler, NetBox
Thanks for the suggestion, however, it didn't help in my case (that relation doesn't seem to exist in the netbox database either).

However, I noticed that 2.8.0 is out, so I tried that, and it works. I did a git bisect, it seems the issue was fixed in my case by:
01b9d1a4939bcf17cb2c37c6e65d619ffd1388f5 is the first bad commit
commit 01b9d1a4939bcf17cb2c37c6e65d619ffd1388f5
Author: Jeremy Stretch <str...@packetlife.net>
Date:   Tue Feb 18 16:03:28 2020 -0500

    Closes #3848: Upgrade to Django 3.0

 netbox/dcim/migrations/0097_mptt.py | 28 ++++++++++++++++++++++++++++
 requirements.txt                    |  6 +++---
 2 files changed, 31 insertions(+), 3 deletions(-)
--
-Austin
GPG: 267B CC1F 053F 0749 (expires 2021/02/18)
Reply all
Reply to author
Forward
0 new messages