FlaskでSQLAlchemyを使用しています
mysqlを使用しており、flask dbコマンドでテーブルの作成まではできています
しかし、flask runで起動すると以下のエラーが発生します
browser
1sqlalchemy.exc.OperationalError 2sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: articles 3[SQL: SELECT articles.id AS articles_id, articles.writer AS articles_writer, articles.title AS articles_title, articles.thumbnail AS articles_thumbnail, articles.content AS articles_content, articles.intro AS articles_intro, articles.release_at AS articles_release_at, articles.created_at AS articles_created_at, articles.updated_at AS articles_updated_at 4FROM articles 5 LIMIT ? OFFSET ?] 6[parameters: (6, 0)] 7(Background on this error at: http://sqlalche.me/e/13/e3q8)
bash
1/Users/nishitatoraki/EYLjapan/application/himasui/himasui_app/himasui_venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py:8 212: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memor 3y:". 4 warnings.warn( 5/Users/nishitatoraki/EYLjapan/application/himasui/himasui_app/himasui_venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py:8 633: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. S 7et it to True or False to suppress this warning. 8 warnings.warn(FSADeprecationWarning( 9 * Debugger is active! 10 * Debugger PIN: 104-727-990 11/Users/nishitatoraki/EYLjapan/application/himasui/himasui_app/himasui_venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py:8 1212: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memor 13y:". 14 warnings.warn( 15/Users/nishitatoraki/EYLjapan/application/himasui/himasui_app/himasui_venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py:8 1633: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. S 17et it to True or False to suppress this warning. 18 warnings.warn(FSADeprecationWarning(
おそらくsqliteのエラーなのですが、mysqlを使っているはずです
flaskの設定ファイルは以下の通りです
local
1import os 2 3 4class DevelopmentConfig: 5 6 # Flask 7 DEBUG = True 8 9 # SQLAlchemy 10 SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://{user}:{password}@{host}/DB名?charset=utf8'.format(**{ 11 'user': os.getenv('DB_USER', 'root'), 12 'password': os.getenv('DB_PASSWORD', ''), 13 'host': os.getenv('DB_HOST', 'localhost'), 14 }) 15 SQLALCHEMY_TRACK_MODIFICATIONS = False 16 SQLALCHEMY_ECHO = False 17 18 19Config = DevelopmentConfig
database
1from flask_sqlalchemy import SQLAlchemy 2from flask_migrate import Migrate 3 4db = SQLAlchemy() 5 6 7def init_db(app): 8 db.init_app(app) 9 Migrate(app, db)
application
1from flask import Flask, render_template 2from database import init_db 3import os 4 5def create_app(): 6 app = Flask(__name__) 7 app.config.from_mapping( 8 SECRET_KEY = 'dev' 9 #DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite') 10 ) 11 app.config.from_pyfile("config/local.py") 12 13 from functions.toppage.toppage import toppage_blueprint 14 app.register_blueprint(toppage_blueprint, url_prefix="/") 15 16 from functions.article_show.article import article_blueprint 17 app.register_blueprint(article_blueprint, url_prefix="/article") 18 19 init_db(app) 20 return app
解決策をご教授いただけるとありがたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/09/23 16:05
2020/09/23 16:14
2020/09/24 11:07