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

Change from Integer to String not detected. #24

Closed
playpianolikewoah opened this Issue Apr 29, 2014 · 10 comments

Comments

Projects
None yet
4 participants
@playpianolikewoah

playpianolikewoah commented Apr 29, 2014

I have a column:
code = db.Column(db.Integer(unsigned=True,zerofill=True))
And when I change that column from Integer to String like so:
code = db.Column(db.String())
And I run:
python manage.py db migrate
the migration does not detect any changes.
Should it not detect at least a change in the column data type?
Migration looks like this after:

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    pass
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    pass
    ### end Alembic commands ###
@miguelgrinberg

This comment has been minimized.

Show comment
Hide comment
@miguelgrinberg

miguelgrinberg Apr 29, 2014

Owner

There is not something this extension does, I'm simply invoking Alembic for the migration work.

See my answer to a similar question in StackOverflow: http://stackoverflow.com/a/17246043/904393. There you can see what Alembic supports and does not support when generating migrations. Column type changes are not supported in the default configuration, but can be enabled.

Owner

miguelgrinberg commented Apr 29, 2014

There is not something this extension does, I'm simply invoking Alembic for the migration work.

See my answer to a similar question in StackOverflow: http://stackoverflow.com/a/17246043/904393. There you can see what Alembic supports and does not support when generating migrations. Column type changes are not supported in the default configuration, but can be enabled.

@playpianolikewoah

This comment has been minimized.

Show comment
Hide comment
@playpianolikewoah

playpianolikewoah Apr 29, 2014

Thanks @miguelgrinberg! That makes sense.
I assume you can just run something like this in your config:

with EnvironmentContext(
    compare_type=true,
)

But how would you use it in the context of Flask-Migrate? Doesn't Flask-Migrate add it's own settings to Alembic?

playpianolikewoah commented Apr 29, 2014

Thanks @miguelgrinberg! That makes sense.
I assume you can just run something like this in your config:

with EnvironmentContext(
    compare_type=true,
)

But how would you use it in the context of Flask-Migrate? Doesn't Flask-Migrate add it's own settings to Alembic?

@miguelgrinberg

This comment has been minimized.

Show comment
Hide comment
@miguelgrinberg

miguelgrinberg Apr 29, 2014

Owner

You have to edit function run_migrations_online() in env.py:

def run_migrations_online():
    # ...
    context.configure(
                connection=connection,
                target_metadata=target_metadata,
                compare_type=True
                )
    # ...
Owner

miguelgrinberg commented Apr 29, 2014

You have to edit function run_migrations_online() in env.py:

def run_migrations_online():
    # ...
    context.configure(
                connection=connection,
                target_metadata=target_metadata,
                compare_type=True
                )
    # ...
@davedg629

This comment has been minimized.

Show comment
Hide comment
@davedg629

davedg629 Jun 19, 2014

I added the compare_type parameter to my env.py but it is still not recognizing the change in one of my column data types. Is there something else I need to do? I'm working within a virtual env if that matters.

davedg629 commented Jun 19, 2014

I added the compare_type parameter to my env.py but it is still not recognizing the change in one of my column data types. Is there something else I need to do? I'm working within a virtual env if that matters.

@miguelgrinberg

This comment has been minimized.

Show comment
Hide comment
@miguelgrinberg

miguelgrinberg Jun 19, 2014

Owner

Have you read the documentation? Type comparison is not always accurate. You can customize it if necessary.

My recommendation, however, is that you edit the migration script by hand. You always need to review migration scripts anyway, so it costs you little to hand edit the type changes.

Owner

miguelgrinberg commented Jun 19, 2014

Have you read the documentation? Type comparison is not always accurate. You can customize it if necessary.

My recommendation, however, is that you edit the migration script by hand. You always need to review migration scripts anyway, so it costs you little to hand edit the type changes.

@davedg629

This comment has been minimized.

Show comment
Hide comment
@davedg629

davedg629 Jun 19, 2014

Alright, guess I need to learn how to do that anyway. Thanks!

davedg629 commented Jun 19, 2014

Alright, guess I need to learn how to do that anyway. Thanks!

@davedg629

This comment has been minimized.

Show comment
Hide comment
@davedg629

davedg629 Jun 19, 2014

I also leave this here for other n00bs that come across this thread:

I was editing the env.py file in the Flask-Migrate package. I needed to edit the env.py in my migrations directory that is created after you run the init command.

davedg629 commented Jun 19, 2014

I also leave this here for other n00bs that come across this thread:

I was editing the env.py file in the Flask-Migrate package. I needed to edit the env.py in my migrations directory that is created after you run the init command.

@miguelgrinberg

This comment has been minimized.

Show comment
Hide comment
@miguelgrinberg

miguelgrinberg Jun 19, 2014

Owner

Yes, that is correct. The env.py in the Flask-Migrate package is a template that is used to generate the env.py in migrations repositories. If you edit the template that will only be used for new migration repositories that you create.

Owner

miguelgrinberg commented Jun 19, 2014

Yes, that is correct. The env.py in the Flask-Migrate package is a template that is used to generate the env.py in migrations repositories. If you edit the template that will only be used for new migration repositories that you create.

@unionx

This comment has been minimized.

Show comment
Hide comment
@unionx

unionx Jan 30, 2015

@davedg629 I add the compare_type args in my env.py, which is created after I ran the init command, but it still did not work. When I was using alembic directly, changing the compare_type arg worked.

unionx commented Jan 30, 2015

@davedg629 I add the compare_type args in my env.py, which is created after I ran the init command, but it still did not work. When I was using alembic directly, changing the compare_type arg worked.

@miguelgrinberg

This comment has been minimized.

Show comment
Hide comment
@miguelgrinberg

miguelgrinberg Apr 26, 2015

Owner

You can now add compare_type=True in the Migrate constructor.

Owner

miguelgrinberg commented Apr 26, 2015

You can now add compare_type=True in the Migrate constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment