Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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
share|improve this question
1  
show config or how you specified the db?.. – Vao Tsun Nov 30 at 8:21
    
what fo you see when you run echo $DATABASE_URL in shell?.. – Vao Tsun Nov 30 at 8:28
    
@VaoTsun postgresql://localhost/app – YAL Nov 30 at 8:38

add postgres driver to the database uri

postgresql+psycopg2://user:password@host:port/dbname
share|improve this answer
    
you meant doing it like this? SQLALCHEMY_DATABASE_URI = os.environ['postgresql+psycopg2://user:password@host:port/db‌​name'] – YAL Nov 30 at 8:46
    
I also got an keyerror message – YAL Nov 30 at 8:55
    
Your database uri environment should contain 'psycopy2' if you are using this driver – metmirr Nov 30 at 8:55
    
got an keyerror message – YAL Nov 30 at 8:56
    
$echo $DATABASE_UR – metmirr Nov 30 at 9:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.