PostgreSQL中字段中的Django ProgrammingError

PostgreSQL中字段中的Django ProgrammingError,第1张

概述models.py class Stop(models.Model): idn = models.PositiveIntegerField(primary_key=True, unique=True) label = models.CharField(null=False, blank=False, max_length=512) coor_x = models.Float models.py
class Stop(models.Model):    IDn = models.PositiveIntegerFIEld(primary_key=True,unique=True)    label = models.CharFIEld(null=False,blank=False,max_length=512)    coor_x = models.floatFIEld()    coor_y = models.floatFIEld()    buses = models.ManyToManyFIEld(Bus)    latest_query_datetime = models.DateTimeFIEld(default=datetime(2000,1,0))    latest_query_data = JsONFIEld(default={})    class Meta:    ordering = ["label"]    def __str__(self):    return self.label

当我跑:

python3 manage.py makemigrations && python3 manage.py migrate

它引发了一个ProgrammingError,说Jsonb数据类型不存在:

Migrations for 'rest':  0007_auto_20160612_1301.py:    - Alter fIEld latest_query_data on stopOperations to perform:  Apply all migrations: ContentTypes,rest,auth,sessions,adminRunning migrations:  Rendering model states... DONE  Applying rest.0005_auto_20160612_1237...Traceback (most recent call last):  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/backends/utils.py",line 64,in execute    return self.cursor.execute(sql,params)psycopg2.ProgrammingError: type "Jsonb" does not existliNE 1: ... table "rest_stop" ADD ColUMN "latest_query_data" Jsonb DEFA...                                                         ^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 "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/core/management/__init__.py",line 353,in execute_from_command_line    utility.execute()  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/core/management/__init__.py",line 345,in execute    self.fetch_command(subcommand).run_from_argv(self.argv)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/core/management/base.py",line 348,in run_from_argv    self.execute(*args,**cmd_options)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/core/management/base.py",line 399,in execute    output = self.handle(*args,**options)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/core/management/commands/migrate.py",line 200,in handle    executor.migrate(targets,plan,fake=fake,fake_initial=fake_initial)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/migrations/executor.py",line 92,in migrate    self._migrate_all_forwards(plan,full_plan,line 121,in _migrate_all_forwards    state = self.apply_migration(state,migration,line 198,in apply_migration    state = migration.apply(state,schema_editor)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/migrations/migration.py",line 123,in apply    operation.database_forwards(self.app_label,schema_editor,old_state,project_state)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/migrations/operations/fIElds.py",line 62,in database_forwards    fIEld,file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/backends/base/schema.py",line 396,in add_fIEld    self.execute(sql,params)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/backends/base/schema.py",line 110,in execute    cursor.execute(sql,params)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/backends/utils.py",line 79,in execute    return super(CursorDeBUGWrapper,self).execute(sql,params)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/utils.py",line 95,in __exit__    six.reraise(dj_exc_type,dj_exc_value,traceback)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/utils/six.py",line 685,in reraise    raise value.with_traceback(tb)  file "/home/erayerdin/.venv/eshot-API/lib/python3.5/site-packages/django/db/backends/utils.py",params)django.db.utils.ProgrammingError: type "Jsonb" does not existliNE 1: ... table "rest_stop" ADD ColUMN "latest_query_data" Jsonb DEFA...

我使用Postgresql来使用JsONFIEld并在用户请求视图时更新它.如果我不使用default = {},它会告诉我创建一个.

更深入的分析

我将latest_query_data字段更改为TextFIEld,以便我可以存储为字符串并在需要时转换为dict.但是,这也引起了同样的错误.

环境

> django 1.9.6
> psycopg 2.6.1

根据Django文档,JsONFIEld要求Postgresql≥9.4且Psycopg2≥2.5.4

您使用的Postgresql版本是什么?

见https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields/#django.contrib.postgres.fields.JSONField

Ubuntu 14.04存储库只包含9.3版本.您可以查看this以升级您的版本.

总结

以上是内存溢出为你收集整理的PostgreSQL中字段中的Django ProgrammingError全部内容,希望文章能够帮你解决PostgreSQL中字段中的Django ProgrammingError所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1164813.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存