Giter Club home page Giter Club logo

Comments (2)

collerek avatar collerek commented on May 18, 2024 2

Actually it should be just

  • for hex: sa.Column('id', sa.CHAR(32), nullable=False),
  • for string: sa.Column('id', sa.CHAR(36), nullable=False),

I changed the column repr method to return char.

It should not use ormar at all but unfortunately by default alembic uses full module name for autoganeration.

To change it you have to pass user_module_prefix='sa.' parameter to context.configure in alembic env.py.
The sa. is the default sqlalchemy prefix, that you can also configure it so if you change it to something different in alembic configuration (sqlalchemy_module_prefix parameter) this one have to match.

"""
***Beginning of the sample revision file***
Revision ID: XXX
Revises: 
Create Date: XXXX-XX-XX

"""
from alembic import op
# alembic by default imports sqlalchemy as sa
# this has to match the set prefix ('sa.' in example above)
import sqlalchemy as sa   

So it should look like this:

(<===trimmed for clarity===>)
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    context.configure(
        url=URL,
        target_metadata=target_metadata,
        literal_binds=True,
        dialect_opts={"paramstyle": "named"},
        # if you use UUID field set also this param
        # the prefix has to match sqlalchemy import name in alembic
        # that can be set by sqlalchemy_module_prefix option (default 'sa.')
        user_module_prefix='sa.'
    )

    with context.begin_transaction():
        context.run_migrations()


def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connectable = create_engine(URL)

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            # if you use UUID field set also this param
            # the prefix has to match sqlalchemy import name in alembic
            # that can be set by sqlalchemy_module_prefix option (default 'sa.')
            user_module_prefix='sa.'
        )

        with context.begin_transaction():
            context.run_migrations()
(<===trimmed for clarity===>)

Please update to 0.5.5 for this feature - also included this in the alembic docs.

from ormar.

hidaris avatar hidaris commented on May 18, 2024

I see the problem now, thanks for the quick fix and instructions!

from ormar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.