数据库迁移是报错(pymysql.err.OperationalError) (1045,

远程链接数据库,进行迁移时,会出现这种错误.

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, “Access denied for user ‘root’@‘localhost’ (using password: YES)”) (Background on this error at: http://sqlalche.me/e/e3q8)

一般是因为你的远程数据库和你项目中的配置文件里,连接数据库的密码不一样导致的.
比如flask项目中的config.py文件中

#数据库的配置信息
SQLALCHEMY_DATABASE_URI = “mysql+pymysql://root:mysql@localhost:3306/information01”

这里的mysql@localhost一定要和你远程数据库中的密码一致.
此时远程数据库的密码必须是mysql,否则就会报错.
密码改成一致之后,再重新迁移,生成迁移脚本,更新数据库,即可.

INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table ‘info_category’
INFO [alembic.autogenerate.compare] Detected added table ‘info_user’
INFO [alembic.autogenerate.compare] Detected added table ‘info_news’
INFO [alembic.autogenerate.compare] Detected added table ‘info_user_fans’
INFO [alembic.autogenerate.compare] Detected added table ‘info_comment’
INFO [alembic.autogenerate.compare] Detected added table ‘info_user_collection’
INFO [alembic.autogenerate.compare] Detected added table ‘info_comment_like’
Generating /root/new_information/migrations/versions/a2560ff9c48b_initial.py … done

更新

python manage.py db upgrade

之后在进数据库查看此时就会有表了.


版权声明:本文为baidu_41825240原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。