Skip to content

Alter timestamp column on Postgres fails due to missing column length #19

@circulon

Description

@circulon

Migrated from: MasoniteFramework/orm#921
Original author: @dapicester
Originally opened: 2025-02-20
Original state: closed


I am migrating from Orator. I have a table where I used to define __timestamps__ = ["created_at"] which seems to be unsupported by Masonite ORM. So I set __timestamps__ = False. The actual column on the database table has no default value, so I add a migration:

class AddDefaultToCreatedAt(Migration):
    def up(self):
        with self.schema.table("mytable") as table:
            table.timestamp("created_at").default("CURRENT_TIMESTAMP(6)").change()

The migration fails with the current error:

  QueryException

  syntax error at or near "None"
  LINE 1: ... "stats" ALTER COLUMN "created_at" TYPE TIMESTAMP(None), ALT...
                                                               ^


  at .venv/lib/python3.9/site-packages/masoniteorm/connections/PostgresConnection.py:222 in query
      218│                     if "SELECT" in cursor.statusmessage:
      219│                         return cursor.fetchall()
      220│                     return {}
      221│         except Exception as e:
    → 222│             raise QueryException(str(e)) from e
      223│         finally:
      224│             if self.get_transaction_level() <= 0:
      225│                 self.open = 0
      226│                 self.close_connection()
make: *** [migrate] Error 1

With a debugger I have been able to debug the Blueprint instance:

> blueprint._last_column.name
'mytable'
> blueprint._last_column.type
'timestamp'
> blueprint._last_column.length
None

I got the migration to complete by manually setting _last_column.length = 6 in the debugger session.
Unfortunately I have not been able to find out where the length is actually set, now why it's set to None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions