Thanks it worked!

*models.py*


class Experiments(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    kountry = db.Column(db.String(100))
    #countryland = db.Column(db.String(100))




*migration file*


from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql


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

    # op.add_column('experiments', sa.Column('kountry', 
sa.String(length=100), nullable=True))
    # op.drop_column('experiments', 'countryland')

    op.alter_column('experiments',
                     column_name = 'countryland',
                     new_column_name = 'kountry',
                     existing_type = sa.String(100),
                     existing_nullable = False,
                     existing_server_default = 'Greenland')

    # ### end Alembic commands ###



Electronically yours,
Mike








On Tuesday, August 27, 2019 at 12:15:06 PM UTC+2, Mike wrote:
>
> *Setup:*
> mysql> SELECT version();
>
> * 5.7.27-0ubuntu0.18.04.1
> * Python 3.6.8
> * SQLAlchemy 1.3.6
> * Alembic 1.0.11
>
>
> *models.py:*
> class Experiments(db.Model):
>     id = db.Column(db.Integer, primary_key=True)
>     # country = db.Column(db.String(100))
>     countryland = db.Column(db.String(100))
>
>     insert_date = db.Column(db.DateTime, index=True,
>         default=datetime.utcnow)
>
>
> *SQL data:*
> INSERT INTO experiments (country)
> VALUES ('US'),
>        ('Canada'),
>        ('Mexico'),
>        ('Brazil'),
>        ('Argentina'),
>        ('Spain'),
>        ('Portugal'),
>        ('France'),
>        ('Germany'),
>        ('UK');
>
>
> *migration file:*
> def upgrade():
>     # ### commands auto generated by Alembic - please adjust! ###
>
>     # op.add_column('experiments', sa.Column('countryland', 
> sa.String(length=100), nullable=True))
>     # op.drop_column('experiments', 'country')
>
>     op.alter_column('experiments', column_name='country', 
> new_column_name='countryland')
>
>     # ### end Alembic commands ###
>
>
>
> *Problem:*
> I want to rename the column name from *"country"* to *"countryland"*. But 
> I'm getting this error in my terminal can anybody help me please?
>
> $ flask db upgrade
>
> [2019-08-27 11:43:26,155] INFO in __init__: microblog startup
> INFO  [alembic.runtime.migration] Context impl MySQLImpl.
> INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
> INFO  [alembic.runtime.migration] Running upgrade 1f866a4fa5a0 -> 
> 69e7cfcf87f1, Testing column rename 02.
> ERROR [root] Error: All MySQL CHANGE/MODIFY COLUMN operations require the 
> existing type.
>
>
> Electronically yours,
> Mike
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy-alembic/01adb38a-0ec5-403b-9825-b1511f41a429%40googlegroups.com.

Reply via email to