我需要以某种方式将v10转储文件转换为9.6兼容的文件
谷歌的Cloud SQL运行PostgreSQL版本9.6,我的数据库自创建以来一直在版本10上运行.
问题:当我尝试将数据库导入Cloud SQL时,我得到了an unknown error has occurred.死亡信息.
我已经尝试在导入到Cloud SQL时评论我的postgis /其他扩展,但无济于事.
我尝试过使用psql my_96_db < my_10.sql并得到大量的错误,如下所示:
...
CREATE TABLE
ERROR: syntax error at or near "AS"
LINE 2: AS integer
^
ERROR: relation "authentication_phonecontact_id_seq" does not exist
CREATE TABLE
...
Run Code Online (Sandbox Code Playgroud)
我已尝试在我的v10 pg_dump -Fc命令上使用postgres 9.6的pg_restore ,但它无法成功导入9.6数据库.输出中许多故障之一的一个例子是
pg_restore: [archiver (db)] could not execute query: ERROR: relation "public.authentication_referral_id_seq" does not exist
LINE 1: SELECT pg_catalog.setval('public.authentication_referral_id_...
^
Command was: SELECT pg_catalog.setval('public.authentication_referral_id_seq', 1, false);
Run Code Online (Sandbox Code Playgroud) 我正在使用 django-model-utils InheritanceManager。我有一个超级通知,我用它来创建多个通知子类,如(models.Model)类PostNotification(Notification),CommentNotification(Notification)等,并试图运行时CommentNotification.objects.bulk_create(list_of_comment_notification_objects),我得到以下回溯:
File "/home/me/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 429, in bulk_create
raise ValueError("Can't bulk create a multi-table inherited model")
ValueError: Can't bulk create a multi-table inherited model
Run Code Online (Sandbox Code Playgroud)
在检查 query.py 文件时,我们发现这会导致错误:
for parent in self.model._meta.get_parent_list():
if parent._meta.concrete_model is not self.model._meta.concrete_model:
raise ValueError("Can't bulk create a multi-table inherited model")
Run Code Online (Sandbox Code Playgroud)
环境 Django Model Utils 版本:3.1.1 Django 版本:1.11.7 Python 版本:2.7.3
PostNotification.objects.bulk_create(
[PostNotification(related_user=user, post=instance) for user in users]
)
Run Code Online (Sandbox Code Playgroud)
抛出上述异常
我虽然只是运行:
BaseClass.objects.bulk_create(list_of_SubClass_objects)而不是SubClass.objects.bulk_create(list_of_SubClass_objects)会工作并返回子类值的列表,但随后运行SubClass.objects.all()会返回一个空结果。bulk_create() 只会为列表中的每个项目创建一个 …
我现在拥有的最佳解决方案.对于大多数人来说,不是pythonic,我希望!
# First Check if at least one of the two values exist in the OrderedDict.
if 'content' in validated_data or 'location' in validated_data:
# If one exists, make sure it is not empty
if 'content' in validated_data:
if not validated_data['content']:
raise MyException("You cannot have blank values")
if 'location' in validated_data:
if not validated_data['location']:
raise MyException("You cannot have blank values")
return validated_data
raise MyException("You need at least one field")
Run Code Online (Sandbox Code Playgroud)