Reputation: 955
I am using flask-migrate to adjust my database changes.
$python manage.py db init
$python manage.py db migrate
These work fine but when i use
$python manage.py db upgrade
This error happens
TypeError: <flask_script.commands.Command object at 0x7fa134712890>: __init__() got an unexpected keyword argument 'length'
This is my models.py
class JobsModel(db.Model):
JOB_STATUS_TYPES = [
(u"data_upload_in_progress", u"Data Upload in Progress"),
(u"data_upload_success", u"Data Upload Success"),
(u"data_validation_success", u"Data Validation Success"),
(u"data_validation_error", u"Data Validation Error")
]
__tablename__ = 'jobs'
job_id = db.Column(db.Integer, primary_key = True)
usecase_id = db.Column(db.Integer, db.ForeignKey('use_cases.id'), nullable = False)
usecase = db.relationship('UseCaseModel')
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
version_id = db.Column(db.Float, nullable=True)
job_status = db.Column(ChoiceType(JOB_STATUS_TYPES))
dataset_id = db.Column(db.Integer, db.ForeignKey('datasets.dataset_id'), nullable=False)
dataset = db.relationship('DataSetModel')
training_details = db.Column(JSON)
testing_details = db.Column(JSON)
This is my file after I do the migrate command 2easaw23523sa.py
from alembic import op
import sqlalchemy as sa
from mi import mig
def upgrade():
op.create_table('jobs',
sa.Column('job_id', sa.Integer(), nullable=False),
sa.Column('usecase_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('version_id', sa.Float(), nullable=True),
sa.Column('job_status', mig.ChoiceType(length=255), nullable=True),
sa.Column('dataset_id', sa.Integer(), nullable=False),
sa.Column('training_details', sa.JSON(), nullable=True),
sa.Column('testing_details', sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(['dataset_id'], ['datasets.dataset_id'], ),
sa.ForeignKeyConstraint(['usecase_id'], ['use_cases.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('job_id')
)
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('jobs')
# ### end Alembic commands ###
Note - statement from mi import mig appears because if used the process given in this answer
Upvotes: 0
Views: 741
Reputation: 665
You can fix this by replacing length=255
with {1:2}
(or any other python object that is Truthy, and can be passed into dict()
without throwing an exception).
i.e. replace the line
sa.Column('job_status', mig.ChoiceType(length=255), nullable=True),
With
sa.Column('job_status', mig.ChoiceType({1:2}), nullable=True),
Upvotes: 1