Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
142 views
in Technique[技术] by (71.8m points)

python 3.x - Flask sqlArchemy, html: ValueError: not enough values to unpack (expected 2, got 1)

I am executing the command flask migrate to create the referring tables more at the moment it starts to run, even though it identifies the tables, it throws the following error. I usually look for and find errors easily, but on this occasion I cannot identify it easily.

PDT: I am new to the subject of programming thanks for the understanding and time.

Mainly what I need is to know where the error is to be able to correct it but the extensions that it calls here do not refer to anything that I have written., Thanks

INFO  [alembic.autogenerate.compare] Detected added column 'blog_user.youtube'
Traceback (most recent call last):
  File "c:usersuserappdatalocalprogramspythonpython38-32lib
unpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:usersuserappdatalocalprogramspythonpython38-32lib
unpy.py", line 87, in _run_code
    exec(code, run_globals)

  File "C:UsersuserDesktopLLACenvScriptsflask.exe\__main__.py", line 7, in <module>
  File "c:usersuserdesktopllacenvlibsite-packagesflaskcli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)

  File "c:usersuserdesktopllacenvlibsite-packagesflaskcli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)

  File "c:usersuserdesktopllacenvlibsite-packagesclickcore.py", line 782, in main
    rv = self.invoke(ctx)

  File "c:usersuserdesktopllacenvlibsite-packagesclickcore.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))

  File "c:usersuserdesktopllacenvlibsite-packagesclickcore.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))

  File "c:usersuserdesktopllacenvlibsite-packagesclickcore.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)

  File "c:usersuserdesktopllacenvlibsite-packagesclickcore.py", line 610, in invoke
    return callback(*args, **kwargs)

  File "c:usersuserdesktopllacenvlibsite-packagesclickdecorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)

  File "c:usersuserdesktopllacenvlibsite-packagesflaskcli.py", line 426, in decorator
    return __ctx.invoke(f, *args, **kwargs)

  File "c:usersuserdesktopllacenvlibsite-packagesclickcore.py", line 610, in invoke
    return callback(*args, **kwargs)

  File "c:usersuserdesktopllacenvlibsite-packagesflask_migratecli.py", line 89, in migrate
    _migrate(directory, message, sql, head, splice, branch_label, version_path,

  File "c:usersuserdesktopllacenvlibsite-packagesflask_migrate\__init__.py", line 96, in wrapped
    f(*args, **kwargs)
  File "c:usersuserdesktopllacenvlibsite-packagesflask_migrate\__init__.py", line 210, in migrate
    command.revision(config, message, autogenerate=True, sql=sql,

  File "c:usersuserdesktopllacenvlibsite-packagesalembiccommand.py", line 221, in revision
    scripts = [script for script in revision_context.generate_scripts()]

  File "c:usersuserdesktopllacenvlibsite-packagesalembiccommand.py", line 221, in <listcomp>
    scripts = [script for script in revision_context.generate_scripts()]

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerateapi.py", line 513, in generate_scripts
    yield self._to_script(generated_revision)

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerateapi.py", line 425, in _to_script
    render._render_python_into_templatevars(

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 49, in _render_python_into_templatevars
    _render_cmd_body(upgrade_ops, autogen_context)

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 71, in _render_cmd_body
    lines = render_op(autogen_context, op)

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 87, in render_op
    lines = util.to_list(renderer(autogen_context, op))

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 179, in _add_table
    for rcons in [

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 180, in <listcomp>
    _render_constraint(cons, autogen_context)

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 775, in _render_constraint
    return renderer(constraint, autogen_context)

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 871, in _render_foreign_key
    "refcols": ", ".join(

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 872, in <genexpr>
    repr(_fk_colspec(f, apply_metadata_schema))

  File "c:usersuserdesktopllacenvlibsite-packagesalembicautogenerate
ender.py", line 808, in _fk_colspec
    tname, colname = tokens[-2:]

ValueError: not enough values to unpack (expected 2, got 1)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am running into the same error. In my case the error disappears if I remove the table_args . Then the migration works so I think it has probably to do with the ForeignKey constraints.

class AccommodationAirport(db.Model):
    __tablename__ = 'accommodation_airport'
    __table_args__ = (
        ForeignKeyConstraint(
        ['supplier'], ['accommodation'],
        name='fk_acco_airp_sup_acco'
        ),
        UniqueConstraint(
            'supplier', 'accommodation', 'airport',
            name='uq_sup_acco_airp'
        )
    )
    created = db.Column(db.DateTime, server_default=func.now())
    last_modified = db.Column(db.DateTime, onupdate=func.now())
    modified_by = db.Column(db.Integer)
    supplier = db.Column(db.String(8), primary_key=True)
    accommodation = db.Column(db.String(32), primary_key=True)
    airport = db.Column(db.String(3), primary_key=True)
    

The only solution I have found so far is to

  1. comment out the table_args with the Constraint declarations,
  2. migrate -> upgrade
  3. uncomment the table_args
  4. migrate -> upgrade

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...