获取OperationalError:没有这样的功能:第一次运行syncdb时的版本

时间:2016-02-17 06:46:37

标签: python django sqlite django-migrations

我为现有的Django代码库设置了一个新环境。但是,我很遗憾无法成功完成./manage.py syncdb./managage.py migrate。这是我的错误输出,包括完整的追溯:

./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

其他信息:
Django版本:1.8.4
Python版本:3.5.1

我的数据库设置:

# 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'),
    }
}

我试图在Django中找到调用任何version()函数的地方,但没有成功。我也试图在OSX上摆弄我的SQLite3版本,但是一直小心翼翼地改变默认的系统版本。在此先感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

好吧,我感到相当愚蠢,因为我完全不知道发生了什么事情,这个答案对我的环境非常具体,对其他人来说相当无用,但我确实让它工作了执行以下操作:

我意识到我的.gitignore文件有一个settings/local.py条目。我检查过,没有local.py文件,但我有一个local.example.py文件。因此,我将该文件复制到local.py示例中,并发现它确实使用django.db.backends.postgresql_psycopg2作为其数据库后端。我认为在项目的迁移文件中的某个地方,发生了Postgres'get_version()函数的特定调用。现在我已经安装了Postgres并为这个项目创建了一个数据库,syncdb命令运行完美。

我的数据库设置现在:

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

很抱歉发送所有帮助我进行疯狂追逐的人。谢谢你的帮助。

答案 1 :(得分:0)

在过去的项目中,我看到了执行手工编写SQL的django(南方)迁移 - 当这些迁移包含db供应商特定代码时,它们无法针对另一个db后端运行。首先,我会检查失败的迁移文件的内容,以确认或排除这种可能性。