'How to fix error in db.create_all() in docker?
Trying to launch postgres and flask in docker. Postgres is working ok as i see. But flask is cancelling to work properly The head of log is here:
Traceback (most recent call last):
File "/app/app.py", line 12, in <module>
db.create_all()
File "/usr/local/lib/python3.10/site-packages/flask_sqlalchemy/__init__.py", line 1094, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
There are models.py
from datetime import datetime
import flask_sqlalchemy
db = flask_sqlalchemy.SQLAlchemy()
class Quiz(db.Model):
__tablename__ = 'quiz'
id = db.Column(db.Integer, primary_key=True)
question = db.Column(db.String(255))
answer = db.Column(db.String(100))
created = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return f"id: {self.id}, answer: {self.answer}, created: {self.created}"
and app.py
import json
from flask import Flask, request
from models import db
import config
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_CONNECTION_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.app_context().push()
db.init_app(app)
db.create_all()
# @app.route('/', methods=['GET'])
@app.route('/')
def hello_world():
return 'Flask Dockerized!'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|