Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
存在排除约束时,Django迁移失败_Django_Postgresql_Django 3.0 - Fatal编程技术网

存在排除约束时,Django迁移失败

存在排除约束时,Django迁移失败,django,postgresql,django-3.0,Django,Postgresql,Django 3.0,我正在尝试将一个排除约束集成到我的模型中,但当我尝试迁移我的PostgreSQL数据库时,它失败了。当我尝试实现文档()给出的示例代码时,它甚至失败了 Iam正在运行Django 3.0.2和PostgreSQL 12 运行迁移时,出现以下错误: me@local % python3 manage.py makemigrations Migrations for 'app': app/migrations/0012_auto_20200106_1941.py - Create mod

我正在尝试将一个排除约束集成到我的模型中,但当我尝试迁移我的PostgreSQL数据库时,它失败了。当我尝试实现文档()给出的示例代码时,它甚至失败了

Iam正在运行Django 3.0.2和PostgreSQL 12

运行迁移时,出现以下错误:

me@local % python3 manage.py makemigrations
Migrations for 'app':
  app/migrations/0012_auto_20200106_1941.py
    - Create model Room
    - Create model Reservation
    - Create constraint exclude_overlapping_reservations on model reservation
me@local % python3 manage.py migrate       
Operations to perform:
  Apply all migrations: admin, auth, authtoken, contenttypes, hr, sessions, app
Running migrations:
  Applying app.0012_auto_20200106_1941...Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedObject: data type integer has no default operator class for access method "gist"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.


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

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 233, in handle
    fake_initial=fake_initial,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/operations/models.py", line 822, in database_forwards
    schema_editor.add_constraint(model, self.constraint)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 362, in add_constraint
    self.execute(sql)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: data type integer has no default operator class for access method "gist"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.
me@local%python3 manage.py makemigrations
“应用程序”的迁移:
app/migrations/0012_auto_20200106_1941.py
-创建模型室
-创建模型预订
-创建约束排除模型保留上的重叠保留
me@local%python3 manage.py迁移
要执行的操作:
应用所有迁移:admin、auth、authtoken、contenttypes、hr、会话、应用程序
运行迁移:
应用应用程序0012_auto_20200106_1941…回溯(最近一次呼叫最后一次):
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/backends/utils.py”,第86行,在
返回self.cursor.execute(sql,params)
psycopg2.errors.UndefinedObject:数据类型integer没有访问方法“gist”的默认运算符类
提示:必须为索引指定运算符类或为数据类型定义默认运算符类。
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“manage.py”,第21行,在
main()
文件“manage.py”,第17行,主
从命令行(sys.argv)执行命令
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/core/management/_init__.py”,第401行,从命令行执行
utility.execute()
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/core/management/__init__.py”,第395行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py”,第328行,在运行时从
self.execute(*args,**cmd_选项)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/core/management/base.py”,执行中第369行
输出=self.handle(*args,**选项)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py”,第83行,包装
res=句柄函数(*args,**kwargs)
handle中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/core/management/commands/migrate.py”,第233行
假首字母=假首字母,
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/migrations/executor.py”,migrate中的第117行
状态=self.\u迁移\u所有\u转发(状态,计划,完整计划,假=假,假首字母=假首字母)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/migrations/executor.py”,第147行,全部向前迁移
state=self.apply\u迁移(state,migration,false=false,false\u initial=false\u initial)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/migrations/executor.py”,第245行,在apply_migration中
state=migration.apply(状态,模式编辑器)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/migrations/migration.py”,应用中的第124行
操作。数据库转发(self.app\u标签、模式编辑器、旧状态、项目状态)
数据库中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/migrations/operations/models.py”,第822行
模式编辑器。添加约束(模型,自约束)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/backends/base/schema.py”,第362行,在add_约束中
self.execute(sql)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/backends/base/schema.py”,执行中的第142行
cursor.execute(sql,params)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/backends/utils.py”,执行中的第100行
return super().execute(sql,params)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/backends/utils.py”,执行中的第68行
返回self.\u使用包装器执行(sql,params,many=False,executor=self.\u execute)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/backends/utils.py”,第77行,带包装器的执行
返回执行器(sql、参数、多个、上下文)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/backends/utils.py”,第86行,在
返回self.cursor.execute(sql,params)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/utils.py”,第90行,在退出时__
使用exc_值的_回溯(回溯)提高dj_exc_值
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/django/db/backends/utils.py”,第86行,在
返回self.cursor.execute(sql,params)
django.db.utils.ProgrammingError:数据类型integer没有访问方法“gist”的默认运算符类
提示:必须为索引指定运算符类或为数据类型定义默认运算符类。

好吧,我只是个傻瓜。RTFM

您必须将
BtreeGistExtension
类添加到迁移中,如文档第一段所述


谢谢@ivissani

您是否按照文档中的说明添加了
b重新注册张力