Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dapicester opened this issue Feb 20, 2025 · 0 comments
Open
Labels
bug An existing feature is not working as intended

Comments

@dapicester
Copy link

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.

@dapicester dapicester added the bug An existing feature is not working as intended label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

No branches or pull requests

1 participant