0

I'm setting up a new environment for an existing Django codebase. However, I am unfortunately unable to successfully complete a ./manage.py syncdb or a ./managage.py migrate. Here is my error output, including full traceback:

./manage.py syncdb
Operations to perform:
  Synchronize unmigrated apps: djcelery, rest_framework_swagger, django_extensions, taggit_serializer, djrill, rest_framework, staticfiles, django_jinja, _humanize, messages, flat, corsheaders
  Apply all migrations: contenttypes, taggit, push, auth, admin, djmail, plug, site, sessions, kombu_transport_django, user, core, grid
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying user.0001_initial...Traceback (most recent call last):
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 316, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: no such function: version

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 "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
    call_command("migrate", **options)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/migrations/migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
    schema_editor.create_model(model)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 236, in create_model
    definition, extra_params = self.column_sql(model, field)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 135, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 625, in db_parameters
    type_string = self.db_type(connection)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django_pgjson/fields.py", line 51, in db_type
    if get_version(connection) < 90200:
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/postgresql_psycopg2/version.py", line 43, in get_version
    cursor.execute("SELECT version()")
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/Users/jamesrasmussen/.virtualenvs/honey-api/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 316, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: no such function: version

Other information:
Django version: 1.8.4
Python version: 3.5.1

My database settings:

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

I have tried to find in Django where any version() function is being called, but with no success. I have also tried to fiddle with my SQLite3 version on OSX, but have been wary to change the default system version. Thanks in advance for the help.

6
  • Can you write your settings.py file, please? Commented Feb 17, 2016 at 7:08
  • @VíctorM updated the question to include my database settings. If you need my whole settings file, a sanitized version of it is here: dpaste.de/bmdE Commented Feb 17, 2016 at 7:12
  • What version of django did the existing codebase use? Commented Feb 17, 2016 at 7:35
  • In my requirements.txt file: Django==1.8.4. All versions using 1.8.4 Commented Feb 17, 2016 at 7:36
  • 1
    @VíctorM I just answered my question. I believe I figured it out. My conjecture is there's some requirement for Postgres' get_version() when Django runs my migration files, though I don't know where and haven't looked enough at Django's migration source to know if that's the case. At any rate, thanks for helping me realize there was a Postgres call in that stack trace, as I would have never searched my codebase for postgres and found that local.example.py file. Commented Feb 17, 2016 at 8:02

2 Answers 2

1

Ok, I feel rather foolish because I don't totally understand what is happening, and this answer is very specific to my environment and rather useless to others, but I did get it to work by doing the following:

I realized that my .gitignore file has an entry for settings/local.py. I checked, and don't have a local.py file, but I do have a local.example.py file. So, I copied that file into a local.py example, and saw that it was indeed using django.db.backends.postgresql_psycopg2 as its database backend. I think that somewhere in the project's migration files, there was a specific call for Postgres' get_version() function happening. Now that I've installed Postgres and created a database for this project, the syncdb command worked flawlessly.

My database settings now:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql_psycopg2",
        "NAME": "honey-api",
    }
}

Sorry to send all that helped me on a wild goose chase. Thanks for your help.

Sign up to request clarification or add additional context in comments.

Comments

0

On a past project I have seen django (south) migrations which executed hand-crafted SQL - when those migrations contain db vendor specific code, they cannot be run against another db backend. So first I would check the content of the failing migration file to confirm or exclude this possibility.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.