IntegrityError: ERROR: null value in column “user_id” violates not-null constraint

喜夏-厌秋 提交于 2019-12-06 07:50:52

First.
   I changed the id naming convention from user_id to simply id in the database (this is true for all others).

class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True)

Second.
   The issue was found in dumping the original sqlite db file into postgres (from sqlite3 --> postgres) instead of creating the db in postgres.
   So, I ran the original code in SQLAlchemy, but this time pointing to the postgres db:

engine = create_engine('postgresql://localhost/some_db')

This created the needed relationships and sequences (shown via \ds in postgres, psql). Issue resolved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!