Skip to content

Commit 464e3d4

Browse files
authored
Merge pull request #38 from TaleLin/dev
feat: 去掉sqlalchemy的warning
2 parents 635db63 + 35eedc3 commit 464e3d4

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

add_super.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22
:copyright: © 2019 by the Lin team.
33
:license: MIT, see LICENSE for more details.
44
"""
5+
from sqlalchemy.exc import IntegrityError
56

67
from app.app import create_app
78
from lin.db import db
89
from lin.core import User
910

10-
app = create_app()
11-
with app.app_context():
12-
with db.auto_commit():
13-
# 创建一个超级管理员
14-
user = User()
15-
user.nickname = 'super'
16-
user.password = '123456'
17-
user.email = '1234995678@qq.com'
18-
# admin 2 的时候为超级管理员,普通用户为 1
19-
user.admin = 2
20-
db.session.add(user)
11+
def main():
12+
app = create_app()
13+
with app.app_context():
14+
with db.auto_commit():
15+
# 创建一个超级管理员
16+
user = User()
17+
user.nickname = 'super'
18+
user.password = '123456'
19+
user.email = '1234995678@qq.com'
20+
# admin 2 的时候为超级管理员,普通用户为 1
21+
user.admin = 2
22+
db.session.add(user)
23+
24+
25+
if __name__ == '__main__':
26+
try:
27+
main()
28+
print("新增超级管理员成功")
29+
except Exception as e:
30+
raise e

app/config/setting.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# 令牌配置
1313
JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)
1414

15+
# 屏蔽 sql alchemy 的 FSADeprecationWarning
16+
SQLALCHEMY_TRACK_MODIFICATIONS = False
17+
1518
# 插件模块暂时没有开启,以下配置可忽略
1619
# plugin config写在字典里面
1720
PLUGIN_PATH = {

0 commit comments

Comments
 (0)