Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Migrations File don't auto import sqlalchemy_utils #1405

Closed
ZackPlauche opened this issue Jan 25, 2024 · 0 comments
Closed

Migrations File don't auto import sqlalchemy_utils #1405

ZackPlauche opened this issue Jan 25, 2024 · 0 comments

Comments

@ZackPlauche
Copy link

Describe the bug

I'm working on an SQLAlchemy backend project. I have a JSONType from sqlalchemy_utils. It's installed in my venv. My code works everywhere else...

sqlalchemy_utils is not appearing in the migrations file as an import for some reason.

Please tell me how to fix this.
Expected behavior

To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved.
See also Reporting Bugs on the website.
Use sqlalchemy_utils JSONType in a field and try to migrate 🤷‍♂️

# Insert code here
from sqlalchemy_utils import JSONType

class Invoice(Base):
    __tablename__ = 'invoices'

    id = Column(Integer, primary_key=True)
    amount = Column(Integer, nullable=False, comment='Amount in cents. Assumes USD.')
    created_at = Column(DateTime, nullable=False)
    platform = Column(String(50), nullable=False)
    platform_id = Column(String(50), nullable=False, unique=True, comment='The id of the invoice on the platform.')
    status = Column(String(50), nullable=False, comment='The status of the invoice on the platform.')
    data = Column(JSONType, nullable=True, comment='The raw data from the platform.')

Error

# Copy error here. Please include the full stack trace.
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [alembic.util.messaging] Target database is not up to date.
FAILED: Target database is not up to date.
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> 0c0645c7a7ab, Update database
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\zackp\.virtualenvs\zackcrm-99W6RUPI\Scripts\alembic.exe\__main__.py", line 7, in <module>
  File "C:\Users\zackp\.virtualenvs\zackcrm-99W6RUPI\Lib\site-packages\alembic\config.py", line 641, in main
    CommandLine(prog=prog).main(argv=argv)
  File "C:\Users\zackp\.virtualenvs\zackcrm-99W6RUPI\Lib\site-packages\alembic\config.py", line 631, in main
    self.run_cmd(cfg, options)
  File "C:\Users\zackp\.virtualenvs\zackcrm-99W6RUPI\Lib\site-packages\alembic\config.py", line 608, in run_cmd
    fn(
  File "C:\Users\zackp\.virtualenvs\zackcrm-99W6RUPI\Lib\site-packages\alembic\command.py", line 403, in upgrade  
    script.run_env()
  File "C:\Users\zackp\.virtualenvs\zackcrm-99W6RUPI\Lib\site-packages\alembic\script\base.py", line 583, in run_env
_module_py
    spec.loader.exec_module(module)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module 
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\zackp\Desktop\zackcrm\backend\crm/database/migrations\env.py", line 84, in <module>
    run_migrations_online()
  File "C:\Users\zackp\Desktop\zackcrm\backend\crm/database/migrations\env.py", line 78, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "C:\Users\zackp\.virtualenvs\zackcrm-99W6RUPI\Lib\site-packages\alembic\runtime\environment.py", line 948, in run_migrations
    self.get_context().run_migrations(**kw)
  File "C:\Users\zackp\.virtualenvs\zackcrm-99W6RUPI\Lib\site-packages\alembic\runtime\migration.py", line 627, in run_migrations
    step.migration_fn(**kw)
  File "C:\Users\zackp\Desktop\zackcrm\backend\crm\database\migrations\versions\0c0645c7a7ab_update_database.py", line 34, in upgrade
    batch_op.add_column(sa.Column('data', sqlalchemy_utils.types.json.JSONType(), nullable=True, comment='The raw data from the platform.'))        
                                          ^^^^^^^^^^^^^^^^
NameError: name 'sqlalchemy_utils' is not defined

Versions.

  • OS: Windows 11
  • Python: 3.11
  • Alembic: 1.13.1
  • SQLAlchemy: 2.0.25
  • Database: db.sqlite3
  • DBAPI: sqlite

Additional context

Have a nice day!

@ZackPlauche ZackPlauche added the requires triage New issue that requires categorization label Jan 25, 2024
@CaselIT CaselIT removed the requires triage New issue that requires categorization label Jan 25, 2024
@sqlalchemy sqlalchemy locked and limited conversation to collaborators Jan 25, 2024
@CaselIT CaselIT converted this issue into discussion #1406 Jan 25, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants