请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

关于flask-sqlacodegen使用方法的报错

图片描述
D:\QinMan\order>flask-sqlacodegen “mysql://root:123456@127.0.0.1/food_db?charse
t=utf8mb4” --tables user --outfile “common/models/User.py” --flask
Traceback (most recent call last):
File “f:\python\lib\runpy.py”, line 170, in run_module_as_main
"main", mod_spec)
File “f:\python\lib\runpy.py”, line 85, in run_code
exec(code, run_globals)
File "F:\python\Scripts\flask-sqlacodegen.exe_main
.py", line 7, in
File “f:\python\lib\site-packages\sqlacodegen\main.py”, line 56, in main
metadata.reflect(engine, args.schema, not args.noviews, tables)
File “f:\python\lib\site-packages\sqlalchemy\sql\schema.py”, line 4208, in re
flect
with bind.connect() as conn:
File “f:\python\lib\site-packages\sqlalchemy\engine\base.py”, line 2209, in c
onnect
return self.connection_cls(self, **kwargs)
File “f:\python\lib\site-packages\sqlalchemy\engine\base.py”, line 103, in __
init

else engine.raw_connection()
File “f:\python\lib\site-packages\sqlalchemy\engine\base.py”, line 2307, in r
aw_connection
self.pool.unique_connection, _connection
File “f:\python\lib\site-packages\sqlalchemy\engine\base.py”, line 2276, in _
wrap_pool_connect
return fn()
File “f:\python\lib\site-packages\sqlalchemy\pool\base.py”, line 303, in uniq
ue_connection
return _ConnectionFairy._checkout(self)
File “f:\python\lib\site-packages\sqlalchemy\pool\base.py”, line 773, in _che
ckout
fairy = _ConnectionRecord.checkout(pool)
File “f:\python\lib\site-packages\sqlalchemy\pool\base.py”, line 492, in chec
kout
rec = pool._do_get()
File “f:\python\lib\site-packages\sqlalchemy\pool\impl.py”, line 139, in do
get
self._dec_overflow()
File “f:\python\lib\site-packages\sqlalchemy\util\langhelpers.py”, line 68, i
n exit
compat.reraise(exc_type, exc_value, exc_tb)
File “f:\python\lib\site-packages\sqlalchemy\util\compat.py”, line 153, in re
raise
raise value
File “f:\python\lib\site-packages\sqlalchemy\pool\impl.py”, line 136, in do
get
return self._create_connection()
File “f:\python\lib\site-packages\sqlalchemy\pool\base.py”, line 308, in _cre
ate_connection
return _ConnectionRecord(self)
File “f:\python\lib\site-packages\sqlalchemy\pool\base.py”, line 437, in in
it

self.__connect(first_connect_check=True)
File “f:\python\lib\site-packages\sqlalchemy\pool\base.py”, line 652, in __co
nnect
connection = pool.invoke_creator(self)
File “f:\python\lib\site-packages\sqlalchemy\engine\strategies.py”, line 114,
in connect
return dialect.connect(*cargs, **cparams)
File “f:\python\lib\site-packages\sqlalchemy\engine\default.py”, line 489, in
connect
return self.dbapi.connect(*cargs, **cparams)
File "f:\python\lib\site-packages\MySQLdb_init
.py", line 86, in Connect
return Connection(*args, **kwargs)
File “f:\python\lib\site-packages\MySQLdb\connections.py”, line 204, in ini
t

super(Connection, self).init(*args, **kwargs2)
TypeError: ‘User’ is an invalid keyword argument for this function

正在回答 回答被采纳积分+3

10回答

编程浪子 2020-03-14 17:54:25

你好

看我的回复呀

https://img1.sycdn.imooc.com//szimg/5e6ca9cf094183a615740960.jpg

1 回复 有任何疑惑可以回复我~
编程浪子 2020-03-15 22:06:05

你好

其实手动生成也可以,你这样,直接去源码把model 复制起来用,等做完了在来看看这什么问题,这样时间充裕


https://git.imooc.com/coding-265/coding-265/src/master/%e5%ae%8c%e6%95%b4%e6%ba%90%e7%a0%81/common/models 

0 回复 有任何疑惑可以回复我~
编程浪子 2020-03-15 17:36:43

你好

你把models下面的__init__.py 删除了在重新执行命令看看

0 回复 有任何疑惑可以回复我~
  • 提问者 纪文 #1
    报的错还是一模一样,难受,这个对接下来的项目影响大吗?
    回复 有任何疑惑可以回复我~ 2020-03-15 20:53:14
提问者 纪文 2020-03-15 14:46:50

这个文件里面

https://img1.sycdn.imooc.com//szimg/5e6dcf3e098bf3b214990847.jpg

0 回复 有任何疑惑可以回复我~
提问者 纪文 2020-03-15 00:46:52

是不是这里出问题了

https://img1.sycdn.imooc.com/szimg/5e6d0a1309e4a27009690294.jpg

0 回复 有任何疑惑可以回复我~
  • 你好
    你这个是哪里来的,截图完整点,有可能
    回复 有任何疑惑可以回复我~ 2020-03-15 10:34:47
  • 提问者 纪文 回复 编程浪子 #2
    我截了图在上面,老师
    回复 有任何疑惑可以回复我~ 2020-03-15 14:47:32
提问者 纪文 2020-03-14 22:37:40

还是这个问题,好奇怪

D:\QinMan\order>flask-sqlacodegen "mysql://root:123456@127.0.0.1/food_db?charset

=utf8mb4" --tables abcd --outfile "common/models/abcd.py" --flask

Traceback (most recent call last):

  File "f:\python\lib\runpy.py", line 170, in _run_module_as_main

    "__main__", mod_spec)

  File "f:\python\lib\runpy.py", line 85, in _run_code

    exec(code, run_globals)

  File "F:\python\Scripts\flask-sqlacodegen.exe\__main__.py", line 7, in <module

>

  File "f:\python\lib\site-packages\sqlacodegen\main.py", line 56, in main

    metadata.reflect(engine, args.schema, not args.noviews, tables)

  File "f:\python\lib\site-packages\sqlalchemy\sql\schema.py", line 4208, in ref

lect

    with bind.connect() as conn:

  File "f:\python\lib\site-packages\sqlalchemy\engine\base.py", line 2209, in co

nnect

    return self._connection_cls(self, **kwargs)

  File "f:\python\lib\site-packages\sqlalchemy\engine\base.py", line 103, in __i

nit__

    else engine.raw_connection()

  File "f:\python\lib\site-packages\sqlalchemy\engine\base.py", line 2307, in ra

w_connection

    self.pool.unique_connection, _connection

  File "f:\python\lib\site-packages\sqlalchemy\engine\base.py", line 2276, in _w

rap_pool_connect

    return fn()

  File "f:\python\lib\site-packages\sqlalchemy\pool\base.py", line 303, in uniqu

e_connection

    return _ConnectionFairy._checkout(self)

  File "f:\python\lib\site-packages\sqlalchemy\pool\base.py", line 773, in _chec

kout

    fairy = _ConnectionRecord.checkout(pool)

  File "f:\python\lib\site-packages\sqlalchemy\pool\base.py", line 492, in check

out

    rec = pool._do_get()

  File "f:\python\lib\site-packages\sqlalchemy\pool\impl.py", line 139, in _do_g

et

    self._dec_overflow()

  File "f:\python\lib\site-packages\sqlalchemy\util\langhelpers.py", line 68, in

 __exit__

    compat.reraise(exc_type, exc_value, exc_tb)

  File "f:\python\lib\site-packages\sqlalchemy\util\compat.py", line 153, in rer

aise

    raise value

  File "f:\python\lib\site-packages\sqlalchemy\pool\impl.py", line 136, in _do_g

et

    return self._create_connection()

  File "f:\python\lib\site-packages\sqlalchemy\pool\base.py", line 308, in _crea

te_connection

    return _ConnectionRecord(self)

  File "f:\python\lib\site-packages\sqlalchemy\pool\base.py", line 437, in __ini

t__

    self.__connect(first_connect_check=True)

  File "f:\python\lib\site-packages\sqlalchemy\pool\base.py", line 652, in __con

nect

    connection = pool._invoke_creator(self)

  File "f:\python\lib\site-packages\sqlalchemy\engine\strategies.py", line 114,

in connect

    return dialect.connect(*cargs, **cparams)

  File "f:\python\lib\site-packages\sqlalchemy\engine\default.py", line 489, in

connect

    return self.dbapi.connect(*cargs, **cparams)

  File "f:\python\lib\site-packages\MySQLdb\__init__.py", line 86, in Connect

    return Connection(*args, **kwargs)

  File "f:\python\lib\site-packages\MySQLdb\connections.py", line 204, in __init

__

    super(Connection, self).__init__(*args, **kwargs2)

TypeError: 'User' is an invalid keyword argument for this function


0 回复 有任何疑惑可以回复我~
提问者 纪文 2020-03-14 22:36:20

版本截图

https://img1.sycdn.imooc.com/szimg/5e6cebd209bb703204860082.jpg

0 回复 有任何疑惑可以回复我~
提问者 纪文 2020-03-14 22:34:53

老师,下面是flask-sqlacodegen的截图

https://img1.sycdn.imooc.com/szimg/5e6ceb63094a946007900795.jpg


0 回复 有任何疑惑可以回复我~
编程浪子 2020-03-14 17:08:20

你好

很奇怪,麻烦你配合我做一些调试步骤

执行如下命令(然后截图)
flask-sqlacodegen
执行如下命令(然后截图)
flask-sqlacodegen --version

如上两步是让我判断软件的。我建议你这样操作一下来验证一下

你把 user 改成 abcd,然后执行

flask-sqlacodegen "mysql://root:123456@127.0.0.1/food_db?charset=utf8mb4" --tables abcd --outfile "common/models/abcd.py" --flask


0 回复 有任何疑惑可以回复我~
  • 提问者 纪文 #1
    嗯嗯,谢谢老师的回复,我在外面吃饭了,我回去试下,看下可不可以都回复您 麻烦您了
    回复 有任何疑惑可以回复我~ 2020-03-14 18:07:45
  • 提问者 纪文 #2
    是不是我的系统问题
    回复 有任何疑惑可以回复我~ 2020-03-14 22:38:19
编程浪子 2020-03-14 16:04:49

你好

试试下面的这个

flask-sqlacodegen "mysql://root:123456@127.0.0.1/food_db?charset=utf8mb4" --tables user --outfile "common/models/user.py" --flask


0 回复 有任何疑惑可以回复我~
  • 提问者 纪文 #1
    还是报一样的错误呢
    回复 有任何疑惑可以回复我~ 2020-03-14 16:07:10
  • 编程浪子 回复 提问者 纪文 #2
    报错应该有区别,报错的最后几行截图我看看
    回复 有任何疑惑可以回复我~ 2020-03-14 16:15:05
  • 提问者 纪文 回复 编程浪子 #3
    File "f:\python\lib\site-packages\sqlalchemy\engine\default.py", line 489, in
     connect
        return self.dbapi.connect(*cargs, **cparams)
      File "f:\python\lib\site-packages\MySQLdb\__init__.py", line 86, in Connect
        return Connection(*args, **kwargs)
      File "f:\python\lib\site-packages\MySQLdb\connections.py", line 204, in __ini
    t__
        super(Connection, self).__init__(*args, **kwargs2)
    TypeError: 'User' is an invalid keyword argument for this function
    回复 有任何疑惑可以回复我~ 2020-03-14 16:18:19
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信