1

I'm using postgres 10.5, python 3, flask and sqlalchemy. I'm trying to create a column in a users table with the following command

id = db.Column(db.Integer, db.Sequence('user_id_seq'), primary_key=True, autoincrement=True)

However, when I run this code and create a user, I get the error: error creating user (psycopg2.ProgrammingError) relation "user_id_seq" does not exist

How can I create the sequence 'user_id_seq' programmatically? Is there some way to check if it exists and create it if it does not using sqlalchemy

2 Answers 2

1

In this case, you will need to create a code to run when starting the bank. for example:

def upgrade():
    op.execute("create sequence user_id_seq start with 1 increment by 1 nocache nocycle")

def downgrade():
    op.execute(sa.schema.DropSequence(sa.Sequence("user_id_seq")))
Sign up to request clarification or add additional context in comments.

Comments

0

Interestingly, this just ended up being a problem with the way my database table was previously defined. I dropped the table, ran the code and the sequence existed correctly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.