title: Flask -- Table (view) already exists (postgresql)
body: <ul>
  <li>Flask version : 2.0.1</li>
  <li>Postgresql: 13.3</li>
  </ul>
  <h2>View:</h2>
  <pre><code>class MarketView(db.Model):
      __table__ = create_view(
          name=&quot;market_view&quot;,
          selectable=select(
              [
                  Tokens.id,
                  Tokens.symbol,
                  Tokens.name,
                  Tokens.tags,
                  Tokens.max_supply,
                  Tokens.circulating_supply,
                  Tokens.total_supply,
                  Tokens.ecosystem,
                  Tokens.consensus,
                  Tokens.category,
                  Tokens.portfolio,
                  Market.usd,
                  Market.btc,
                  Market.cmc_rank,
                  Market.trust_score,
                  Indicator.rsi,
                  Indicator.stochastic,
                  Indicator.bollinger,
                  Indicator.cci,
                  Indicator.cfi,
                  Indicator.ema,
                  Indicator.evm,
                  Indicator.macd,
                  Indicator.roc,
              ],
              from_obj=(
                  Tokens.__table__.join(
                      Market, Tokens.id == Market.token_id
                  ).join(Indicator, Tokens.id == Indicator.token_id)
              ),
          ),
          metadata=db.metadata,
      )
  </code></pre>
  <h2>Init</h2>
  <pre><code>def configure_database(app):
      @app.before_first_request
      def initialize_database():
          try:
              db.create_all()
          except ProgrammingError:
              pass
  
      @app.teardown_request
      def shutdown_session(exception=None):
          db.session.remove()
  </code></pre>
  <p>I don't know how to fix this. To resolve it (ugly way) I've used the exception ProgrammingError &quot;except ProgrammingError: pass&quot;</p>
  <p>Any help to resolve this case ?</p>
  <p>Thanks!</p>