flask db migrate adds project name to generated script

72 Views Asked by At

When I run flask db upgrade, I am getting this error

  File "/Users/user/Development/projects/zen/zen_api/zen_api/migrations/versions/88e9c6a7b904_.py", line 23, in upgrade
    sa.Column('first_name', sa.String(length=zen_api.config.Config['NAME_LENGTH']), nullable=False),
                                             ^^^^^^^
NameError: name 'zen_api' is not defined

I'm not sure why when I run flask db migrate a migration script is generated with zen_api.config.Config[...]. This causes the following error when flask db upgrade is ran

    sa.String(length=zen_api.config.Config["NAME_LENGTH"]),
                     ^^^^^^^
NameError: name 'zen_api' is not defined

migration script generated

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('last_name', sa.String(length=zen_api.config.Config['NAME_LENGTH']), nullable=False),
    sa.Column('email', sa.String(length=zen_api.config.Config['EMAIL_LENGTH']), nullable=False),
    sa.PrimaryKeyConstraint('id')

Should I be adding import zen_api to the script.py.mako? I"m new to flask and I'm not sure if this is the proper way to do things or if there a better approach.

File structure for my project

/zen_api
  /tests
  /zen_api
    /migrations
      /versions
        88efjd8f_.py
    /models
0

There are 0 best solutions below