question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transaction table not being created.

See original GitHub issue

Pyramid/SQLAlchemy project, using alembic the version tables are being created fine but the Transaction table is not so when changes are made, I get the error:

ProgrammingError: (psycopg2.ProgrammingError) relation "transaction" does not exist LINE 1: INSERT INTO transaction (fxt, issued_at, id, remote_addr) VA... ^ [SQL: "INSERT INTO transaction (fxt, issued_at, id, remote_addr) VALUES (%(fxt)s, %(issued_at)s, nextval('transaction_id_seq'), %(remote_addr)s) RETURNING transaction.id"] [parameters: {'fxt': None, 'issued_at': datetime.datetime(2020, 1, 28, 23, 1, 46, 849596), 'remote_addr': None}] (Background on this error at: http://sqlalche.me/e/f405) Not doing anything fancy, just using the make_versioned/configure_mappers calls as in the examples.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rs-richardlaucommented, Apr 12, 2021

I had a similar issue.

If you are using Alembic but NOT using Flask, then you need to manually import the models that are using versioning in alembic/env.py, and then you can run the revision auto-generating feature of Alembic.

The below is a solution that doesn’t require you to manually create migration files. It’s not the cleanest, so I’m sure someone could suggest a neater way to do it.


My models/__init__.py:

from sqlalchemy_continuum import make_versioned

make_versioned(user_cls=None)

My alembic/env.py:

. . .

from sqlalchemy.orm import configure_mappers 
from models.report import Report  # the model(s) that needs versioning

configure_mappers() # You need to call this after the import
. . .

Then you run:

pipenv run alembic revision --autogenerate -m "<revision message>"

This should create a migration file that creates the reports_version table (<your model>_version instead) and transaction table, along with all necessary indices. If you have more models to version, just add their imports before configure_mappers()

0reactions
KeironOcommented, Dec 29, 2020

Oh wow, that was easy.

So, I created a table as I would any other:

class Transaction(Base):
    issued_at = db.Column(db.DateTime(), nullable=True)
    remote_addr = db.Column(db.String(50), nullable=True)

And it works 😄

Thank you, just need to get it to play nicely with marshmallow and we’re off to the races.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How create table behaves in transactions? - Stack Overflow
Your table wasn't created because you didn't commit TRANSACTION as well as your insert wasn't performed. Reason why you are getting result
Read more >
Reading from table being created in transaction
Now, if I open a new query, and do a regular select statement, I will not get any results, the wheel will be...
Read more >
CREATE TABLE and INSERT fail in same Transaction #14548
A workaround is to not use placeholder variables when running an INSERT following a CREATE TABLE in the same transaction.
Read more >
How to Create a table in the middle of a transaction
Issuing DDL in the middle of a transaction is a very bad idea and usually signifies a poorly designed process. Is there really...
Read more >
Transaction Table - an overview | ScienceDirect Topics
It is not necessary in MongoDB to explicitly create the collection; the collection is created the first time an object is inserted into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found