1

I have been following everything in this tutorial for Postgres:https://realpython.com/blog/python/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/

And I have been getting the following error. I don't understand why my system keeps on choosing to use SQLite when I had specifically set up everything for using Postgres.

    (table.description, column.name, ce.args[0])
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 202, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 2329, in visit_create_table
    and not first_pk)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 242, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 81, in _compiler_dispatch
    return meth(self, **kw)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 2360, in visit_create_column
    first_pk=first_pk
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/dialects/sqlite/base.py", line 865, in get_column_specification
    column.type, type_expression=column)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 290, in process
    return type_._compiler_dispatch(self, **kw)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 79, in _compiler_dispatch
    raise exc.UnsupportedCompilationError(visitor, cls)
sqlalchemy.exc.CompileError: (in table 'results', column 'result_all'): Compiler <sqlalchemy.dialects.sqlite.base.SQLiteTypeCompiler object at 0x1110e4090> can't render element of type <class 'sqlalchemy.sql.sqltypes.JSON'>

This is what I have for views.py

from flask import render_template
#from app import app
from flask import Flask
from flask import Flask, flash, redirect, render_template, request, session, abort
from flask_sqlalchemy import SQLAlchemy
import os


app = Flask(__name__)
app.config.from_pyfile('../config.py')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)

from models import Result

And this is my Config.py

import os
basedir = os.path.abspath(os.path.dirname(__file__))


class Config(object):
    DEBUG = False
    TESTING = False
    CSRF_ENABLED = True
    SECRET_KEY = 'this-really-needs-to-be-changed'
    SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']


class ProductionConfig(Config):
    DEBUG = False


class StagingConfig(Config):
    DEVELOPMENT = True
    DEBUG = True


class DevelopmentConfig(Config):
    DEVELOPMENT = True
    DEBUG = True


class TestingConfig(Config):
    TESTING = True
3
  • 1
    show config or how you specified the db?.. Commented Nov 30, 2016 at 8:21
  • what fo you see when you run echo $DATABASE_URL in shell?.. Commented Nov 30, 2016 at 8:28
  • @VaoTsun postgresql://localhost/app Commented Nov 30, 2016 at 8:38

1 Answer 1

1

add postgres driver to the database uri

postgresql+psycopg2://user:password@host:port/dbname
Sign up to request clarification or add additional context in comments.

7 Comments

you meant doing it like this? SQLALCHEMY_DATABASE_URI = os.environ['postgresql+psycopg2://user:password@host:port/dbname']
Your database uri environment should contain 'psycopy2' if you are using this driver
$echo $DATABASE_UR
$echo $DATABASE_URI
$echo $DATABASE_URI should give you this output: postgresql+psycopg2://user:password@host:port/dbname
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.