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

来源:7-2 登陆退出准备工作,数据库GUI工具演示

纪文

2020-03-14

图片描述
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

写回答

10回答

编程浪子

2020-03-14

你好

看我的回复呀

//img.mukewang.com/szimg/5e6ca9cf094183a615740960.jpg

1
0

编程浪子

2020-03-15

你好

其实手动生成也可以,你这样,直接去源码把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
0

编程浪子

2020-03-15

你好

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

0
1
纪文
报的错还是一模一样,难受,这个对接下来的项目影响大吗?
2020-03-15
共1条回复

纪文

提问者

2020-03-15

这个文件里面

//img.mukewang.com/szimg/5e6dcf3e098bf3b214990847.jpg

0
0

纪文

提问者

2020-03-15

是不是这里出问题了

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

0
2
纪文
回复
编程浪子
我截了图在上面,老师
2020-03-15
共2条回复

纪文

提问者

2020-03-14

还是这个问题,好奇怪

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
0

纪文

提问者

2020-03-14

版本截图

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

0
0

纪文

提问者

2020-03-14

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

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


0
0

编程浪子

2020-03-14

你好

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

执行如下命令(然后截图)
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
2
纪文
是不是我的系统问题
2020-03-14
共2条回复

编程浪子

2020-03-14

你好

试试下面的这个

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


0
4
纪文
回复
编程浪子
这个应该要怎么解决呢,老师
2020-03-14
共4条回复

Python Flask构建微信小程序订餐系统(可用于毕设)

微信小程序 + Python Flask 打造订餐系统全栈应用,可用于毕设。

1709 学习 · 1889 问题

查看课程