skip to Main Content

I am trying to add a new row to my table enjordplatform_keywords but everytime I do that it instead tries to add the row in the middle of the table.
Usually that id that it is trying to insert it in is taken but sometimes (if I have removed a row say row 81 it will add the new values in the empty row 81). Though the table goes up to 474 so why doesn’t it add it in 475 instead of in the middle of the table.
This happens if I try to do it through sqlalchemy and if I try to do it directly in the database.
It has worked perfectly fine but then this happened for some unknown reason.

What could be the problem?

This is the table in sqlalchemy:

class enjordplatformKeywords(Base):
    __tablename__ = "enjordplatform_keywords"
    id = Column(Integer, primary_key=True, unique=True)
    keyword = Column(String)
    keyword_swedish = Column(String)
    question_id = Column(Integer,ForeignKey("enjordplatform_quiz.id"))
    times_clicked = Column(Integer)
    added_by_company = Column(Integer)
    english_added = Column(Integer)

Here is an example of when I am inserting a new record directly into the postgres database and the error it gives.

My insert

insert into enjordplatform_keywords (keyword, keyword_swedish) VALUES ('Artificial Intelligence', 'Artificial Intelligence');

The error message

ERROR:  duplicate key value violates unique constraint "enjordplatform_keywords_pkey"
DETALJ:  Key (id)=(86) already exists.

The postgres database has 430 rows and previously it would get id 431 when inserting a new record instead of trying to override id=86


Please signup or login to give your own answer.
Back To Top
Search