- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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, 1, 0, 0, 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 stop
Operations to perform:
Apply all migrations: contenttypes, rest, auth, sessions, admin
Running 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 exist
LINE 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, fake=fake, fake_initial=fake_initial)
File "/home/erayerdin/.venv/eshot-api/lib/python3.5/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/erayerdin/.venv/eshot-api/lib/python3.5/site-packages/django/db/migrations/executor.py", 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/backends/utils.py", line 64, in execute
return self.cursor.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", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: type "jsonb" does not exist
LINE 1: ... TABLE "rest_stop" ADD COLUMN "latest_query_data" jsonb DEFA...
我使用 PostgreSQL 来使用 JSONField 并在用户请求 View 时更新它。如果我不使用 default={}
,它会告诉我做一个。
我将 latest_query_data
字段更改为 TextField
以便我可以存储为字符串并在需要时转换为 dict
。但是,这也引发了同样的错误。
最佳答案
根据 Django 文档,JSONField 需要 PostgreSQL ≥ 9.4 和 Psycopg2 ≥ 2.5.4
您使用的是什么 PostgreSQL 版本?
Ubuntu 14.04 存储库仅包含 9.3 版本。您可以查看this升级您的版本。
关于PostgreSQL 字段中的 Django ProgrammingError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37773005/
我使用带有 Flask 的 Postgresql 使用 SQLAlchemy 有以下数据库结构: class Attendance(db.Model): id = db.Column(db.Int
我正在通过创建新项目来尝试 Pyramid。我选择 PostgreSQL 和 sqlalchemy。现在我有一个手动创建的表格“照片”和一个模型: class Photo(Base): """
我正在尝试使用查询插入数据框 engine = create_engine('scot://pswd:xyz@ hostnumb:port/db_name') dataframe.to_sql('ta
我正在使用 pandas 创建一个 python 脚本来读取具有多个行值的文件。 读取后,我需要构建这些值的数组,然后将其分配给数据框行值。 我用过的代码是 import re import nump
这是我的查询: QUERY = """ UPDATE my_table SET my_prop=:foo WHERE hello
我正在尝试查询 Version,我希望将对象返回到它们的 max_version_number 属性等于 version_number 的位置: latest_versions = \ dbS
我有这个功能。我想要获取每个项目的照片ID数组,但得到一个错误
我在尝试测试是否可以将一些记录保存到数据库中时遇到了问题。我使用 postgres.app 作为数据库。在尝试测试之前,我做了: dropdb testdb createdb testdb pytho
我正在开发一个基于 http://code.tutsplus.com/tutorials/intro-to-flask-signing-in-and-out--net-29982 的 flask 应用
在 heroku 上设置新数据库我试过 python manage migrate并得到许多与 relation already exists/does not exists 相关的异常.所以我按照这
I am getting this Exception in my browser, I have seen upto 20 posts related to this error but I cou
因此,我更改了用于我的 Django 应用程序的设备。为了更换设备,我只是将整个存储库复制粘贴到新设备,设置数据库,运行假迁移,然后当应用程序运行良好时,再次开始开发。 但是,当我开始在 Django
因此,我更改了用于我的 Django 应用程序的设备。为了更换设备,我只是将整个存储库复制粘贴到新设备,设置数据库,运行假迁移,然后当应用程序运行良好时,再次开始开发。 但是,当我开始在 Django
使用python的MySQLDB连接到MariaDB数据库;我正在运行 SELECT 的良性循环,由于某些未知原因而中断 _mysql_exceptions.ProgrammingError: (20
这是我的源代码: @app.route('/pythonlogin/register', methods=['GET', 'POST']) def register(): # Output m
模型.py class Stop(models.Model): idn = models.PositiveIntegerField(primary_key=True, unique=True)
我目前正在尝试将我的 Flask 应用程序部署到 Heroku,但我在数据库初始化期间遇到错误。 这是我的 models.py 文件: from app import app from app im
我正在使用 ipdb 调试器在本地调试多线程 Web 应用程序(Django、Plone)。通常 ipdb 似乎因为在调试提示符下发生的自动重新加载而感到困惑。生成的堆栈跟踪出现 /Users/mik
我正在尝试通过使用MRjob填充一个postgresql数据库。几天前,有人好心地建议我here将映射器分步进行。我试过但是给出了一个错误: python db_store_hadoop.py -r
我只是看不出此错误的原因。我在 phpMyAdmin 中尝试了相同的 SQL,它工作得很好,但在 Python 中尝试时失败了。 带有 SQL 查询的 Python 代码: cursor.execut
我是一名优秀的程序员,十分优秀!