简体   繁体   English

Flask SQLAlchemy null “id”列中的值违反非空约束

[英]Flask SQLAlchemy null value in column "id" violates not-null constraint

I have a web application and two different environments: prod and staging.我有一个 web 应用程序和两个不同的环境:prod 和 staging。

I exported tables from one database to another, from production to staging.我将表从一个数据库导出到另一个数据库,从生产到暂存。 Now the staging database got all the tables however, whenever I try to use the staging web application to create a model, I get:现在暂存数据库获得了所有表,但是,每当我尝试使用暂存 web 应用程序创建 model 时,我得到:

sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "id" violates not-null constraint

I then realized that the staging database didn't have any sequences so I copied over the sequences from the prod env to the staging env too.然后我意识到暂存数据库没有任何序列,所以我也将序列从生产环境复制到暂存环境。 However I still get that error.但是我仍然收到该错误。 I'm not sure what the issue is.我不确定是什么问题。 It's similar to the question here however unlike the answer there I'm exporting the tables from a postgres db to another postgres db.它类似于此处的问题,但与那里的答案不同,我将表从 postgres 数据库导出到另一个 postgres 数据库。

Any insight would be appreciated任何见解将不胜感激

In this case, it seems that you might use a kind database migration tool, it created some additional tables to keep tracking and cause the issue.在这种情况下,您似乎可以使用一种数据库迁移工具,它创建了一些额外的表来保持跟踪并导致问题。 The solution is that you need to export crucial tables (which you defined on your own) from your old DB then dump to CSV, JSON then, loads to postgresql again.解决方案是您需要从旧数据库中导出关键表(您自己定义的)然后转储到 CSV、JSON,然后再次加载到 postgresql。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ user_id”列中的空值违反了非空约束 - null value in column “user_id” violates not-null constraint “ city_id”列中的空值违反了非空约束 - null value in column “city_id” violates not-null constraint “ job_id”列中的空值违反了非空约束 - null value in column “job_id” violates not-null constraint Django:关系的“id”列中的 null 值违反非空约束 - Django : null value in column "id" of relation violates not-null constraint 保存ModelForm时,列中的null值违反非空约束 - null value in column violates not-null constraint while saving ModelForm Django:“is_admin”列中的 null 值违反了非空约束 - Django: null value in column "is_admin" violates not-null constraint Django-“ imageLink”列中的空值违反了非空约束 - Django - Null value in column “imageLink” violates not-null constraint Django - 列中的空值违反了 Django 管理中的非空约束 - Django - null value in column violates not-null constraint in Django Admin “ user_id”列中的null值违反了非null约束Django - null value in column “user_id” violates not-null constraint Django IntegrityError:错误:“ user_id”列中的空值违反了非空约束 - IntegrityError: ERROR: null value in column “user_id” violates not-null constraint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM