22

I have a postgres DB, which I manage through SQLAlchemy and alembic (for migrations). When creating a DB migration through alembic, I get the following INFO in the console.

INFO  [alembic.ddl.postgresql] Detected sequence named 'my_table_name_id_seq' as owned by integer column 'my_table_name(id)', assuming SERIAL and omitting

My model looks like

class CopyJob(db.Model):
    __tablename__ = "my_table_name"

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

I interpret the above as a warning. One line is generated for each of my tables. I have two questions:

  • Am I doing something wrong when getting the warning above
  • What should I fix / explicitly set, in order to make it go away. Migrations are too verbose.

Thank you!

Andrei Cioara
  • 3,404
  • 5
  • 34
  • 62
  • 4
    You have your alembic logging level set to INFO. So, it's not even a warning. It's just info. Change your logging level to WARN if you don't want to see INFO lines. It's probably in the alembic.ini configuration file, the logger_alembic section. https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file – clockwatcher Jul 06 '19 at 07:16
  • 4
    That is one possibility, but I prefer to keep the INFO logging level and just address these particular lines. Do you think that is possible? – Andrei Cioara Jul 06 '19 at 07:30
  • 1
    You should be able to do it with a logging.Filter (https://docs.python.org/2/library/logging.html#filter-objects). But assuming you're using the command-line alembic script to launch alembic adding a filter to its logging handler isn't something you're going to be able to do through configuration. Filters aren't supported by logging.config.fileConfig which is what alembic is using. You'd need to launch alembic programmatically so you can set up the logger yourself. Another option is to patch out the log call in the PostgresqlImpl.autogen_col_reflect method. – clockwatcher Jul 06 '19 at 08:53
  • @AndreiCioara you can filter logs by utilizing the `qualname` . For instance : `qualname = alembic.env` – Lekhnath Apr 27 '22 at 09:01

1 Answers1

5

After digging a bit into alembic code it doesn't look like a warning. Alembic just informs that the sequence it checks turns out to be a SERIAL. Therefore, there's no point in trying to somehow fix the issue. If the message bothers you, you can increase the log level to WARNING as was suggested in the comments, otherwise, there seems to be no workaround.

Roman Nakutnyi
  • 791
  • 7
  • 11
  • 1
    That says what happens... When you put serial as column type PG creates column of integers, sequence named - table_column_seq - and marks table as owner of the sequence. Probably developers decided to flex a bit by showing it to you... ;) – Michał Zaborowski Dec 01 '21 at 16:42